<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[286762] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/286762">286762</a></dd>
<dt>Author</dt> <dd>megan_gardner@apple.com</dd>
<dt>Date</dt> <dd>2021-12-08 21:27:01 -0800 (Wed, 08 Dec 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>Show correct content menu for images services chevron.
https://bugs.webkit.org/show_bug.cgi?id=233970

Reviewed by Tim Horton.

Add support for showing the correct context menu for image services.
Since this is internal only and can never be affected by web content, we bypass
the web content round trip and directly message the UIProcess about showing
a context menu for images. And because it would be bizarre if the web content
could prevent a menu from popping up on a button they have no control over.

Source/WebCore:

* dom/mac/ImageControlsMac.cpp:
(WebCore::ImageControlsMac::isImageControlsButtonElement):
(WebCore::ImageControlsMac::imageFromImageElementNode):
(WebCore::ImageControlsMac::handleEvent):
(WebCore::ImageControlsMac::imageControlHost): Deleted.
* dom/mac/ImageControlsMac.h:
* html/HTMLButtonElement.cpp:
(WebCore::HTMLButtonElement::defaultEventHandler):
* page/ChromeClient.h:
(WebCore::ChromeClient::handleImageServiceClick):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::maybeCreateContextMenu):
(WebCore::imageFromImageElementNode): Deleted.

Source/WebKit:

* Shared/ContextMenuContextData.cpp:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::m_selectionIsEditable):
(WebKit::ContextMenuContextData::setImage):
(WebKit::ContextMenuContextData::controlledDataIsEditable const):
* Shared/ContextMenuContextData.h:
(WebKit::ContextMenuContextData::webHitTestResultData):
(WebKit::ContextMenuContextData::webHitTestResultData const):
* UIProcess/WebContextMenuProxy.cpp:
(WebKit::WebContextMenuProxy::show):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::contextMenuItemSelected):
* UIProcess/mac/WebContextMenuProxyMac.mm:
(WebKit::WebContextMenuProxyMac::getShareMenuItem):
(WebKit::WebContextMenuProxyMac::getContextMenuFromItems):
(WebKit::WebContextMenuProxyMac::useContextMenuItems):
* UIProcess/mac/WebPageProxyMac.mm:
(WebKit::WebPageProxy::handleContextMenuQuickLookImage):
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::handleImageServiceClick):
* WebProcess/WebCoreSupport/WebChromeClient.h:
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::handleImageServiceClick):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoredommacImageControlsMaccpp">trunk/Source/WebCore/dom/mac/ImageControlsMac.cpp</a></li>
<li><a href="#trunkSourceWebCoredommacImageControlsMach">trunk/Source/WebCore/dom/mac/ImageControlsMac.h</a></li>
<li><a href="#trunkSourceWebCorehtmlHTMLButtonElementcpp">trunk/Source/WebCore/html/HTMLButtonElement.cpp</a></li>
<li><a href="#trunkSourceWebCorepageChromeClienth">trunk/Source/WebCore/page/ChromeClient.h</a></li>
<li><a href="#trunkSourceWebCorepageContextMenuControllercpp">trunk/Source/WebCore/page/ContextMenuController.cpp</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitSharedContextMenuContextDatacpp">trunk/Source/WebKit/Shared/ContextMenuContextData.cpp</a></li>
<li><a href="#trunkSourceWebKitSharedContextMenuContextDatah">trunk/Source/WebKit/Shared/ContextMenuContextData.h</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebContextMenuProxycpp">trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessWebPageProxycpp">trunk/Source/WebKit/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKitUIProcessmacWebContextMenuProxyMacmm">trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKitUIProcessmacWebPageProxyMacmm">trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebCoreSupportWebChromeClientcpp">trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebCoreSupportWebChromeClienth">trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPageWebPageh">trunk/Source/WebKit/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKitWebProcessWebPagemacWebPageMacmm">trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebCore/ChangeLog      2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -1,3 +1,30 @@
</span><ins>+2021-12-08  Megan Gardner  <megan_gardner@apple.com>
+
+        Show correct content menu for images services chevron.
+        https://bugs.webkit.org/show_bug.cgi?id=233970
+
+        Reviewed by Tim Horton.
+
+        Add support for showing the correct context menu for image services.
+        Since this is internal only and can never be affected by web content, we bypass
+        the web content round trip and directly message the UIProcess about showing 
+        a context menu for images. And because it would be bizarre if the web content 
+        could prevent a menu from popping up on a button they have no control over.
+
+        * dom/mac/ImageControlsMac.cpp:
+        (WebCore::ImageControlsMac::isImageControlsButtonElement):
+        (WebCore::ImageControlsMac::imageFromImageElementNode):
+        (WebCore::ImageControlsMac::handleEvent):
+        (WebCore::ImageControlsMac::imageControlHost): Deleted.
+        * dom/mac/ImageControlsMac.h:
+        * html/HTMLButtonElement.cpp:
+        (WebCore::HTMLButtonElement::defaultEventHandler):
+        * page/ChromeClient.h:
+        (WebCore::ChromeClient::handleImageServiceClick):
+        * page/ContextMenuController.cpp:
+        (WebCore::ContextMenuController::maybeCreateContextMenu):
+        (WebCore::imageFromImageElementNode): Deleted.
+
</ins><span class="cx"> 2021-12-08  Myles C. Maxfield  <mmaxfield@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [MacCatalyst] Fix Mac Catalyst build
</span></span></pre></div>
<a id="trunkSourceWebCoredommacImageControlsMaccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/mac/ImageControlsMac.cpp (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/mac/ImageControlsMac.cpp        2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebCore/dom/mac/ImageControlsMac.cpp   2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -26,9 +26,14 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "ImageControlsMac.h"
</span><span class="cx"> 
</span><ins>+#include "Chrome.h"
+#include "ChromeClient.h"
+#include "ContextMenuController.h"
</ins><span class="cx"> #include "ElementInlines.h"
</span><ins>+#include "EventHandler.h"
</ins><span class="cx"> #include "HTMLButtonElement.h"
</span><span class="cx"> #include "HTMLDivElement.h"
</span><ins>+#include "HTMLImageElement.h"
</ins><span class="cx"> #include "HTMLNames.h"
</span><span class="cx"> #include "HTMLStyleElement.h"
</span><span class="cx"> #include "RenderImage.h"
</span><span class="lines">@@ -62,26 +67,9 @@
</span><span class="cx">     return shadowRoot->hasElementWithId(*imageControlsElementIdentifier().impl());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static RefPtr<HTMLElement> imageControlHost(const Node& node)
-{
-    auto host = node.shadowHost();
-    if (!is<HTMLElement>(host))
-        return nullptr;
-
-    RefPtr element { &downcast<HTMLElement>(*host) };
-    return hasControls(*element) ? element : nullptr;
-}
-
</del><span class="cx"> bool isImageControlsButtonElement(const Node& node)
</span><span class="cx"> {
</span><del>-    auto host = imageControlHost(node);
-    if (!host)
-        return false;
-
-    if (RefPtr controlRoot = static_cast<TreeScope&>(*host->userAgentShadowRoot()).getElementById(imageControlsButtonIdentifier()))
-        return node.isDescendantOf(*controlRoot);
-
-    return false;
</del><ins>+    return is<Element>(node) && downcast<Element>(node).getIdAttribute() == imageControlsButtonIdentifier();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void createImageControls(HTMLElement& element)
</span><span class="lines">@@ -105,6 +93,51 @@
</span><span class="cx">         downcast<RenderImage>(*renderObject).setHasShadowControls(true);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static Image* imageFromImageElementNode(Node& node)
+{
+    auto* renderer = node.renderer();
+    if (!is<RenderImage>(renderer))
+        return nullptr;
+    auto* image = downcast<RenderImage>(*renderer).cachedImage();
+    if (!image || image->errorOccurred())
+        return nullptr;
+    return image->imageForRenderer(renderer);
+}
+
+bool handleEvent(HTMLElement& element, Event& event)
+{
+    if (event.type() != eventNames().clickEvent)
+        return false;
+    
+    RefPtr frame = element.document().frame();
+    if (!frame)
+        return false;
+
+    Page* page = element.document().page();
+    if (!page)
+        return false;
+    
+    if (!is<MouseEvent>(event))
+        return false;
+    
+    auto& mouseEvent = downcast<MouseEvent>(event);
+    if (!is<Node>(mouseEvent.target()))
+        return false;
+    auto& node = downcast<Node>(*mouseEvent.target());
+
+    if (ImageControlsMac::isImageControlsButtonElement(node)) {
+        auto imageElement = node.shadowHost();
+        if (!imageElement)
+            return false;
+        if (auto* image = imageFromImageElementNode(*imageElement)) {
+            page->chrome().client().handleImageServiceClick(roundedIntPoint(mouseEvent.absoluteLocation()), *image, imageElement->isContentEditable());
+            event.setDefaultHandled();
+            return true;
+        }
+    }
+    return false;
+}
+
</ins><span class="cx"> #endif // ENABLE(SERVICE_CONTROLS)
</span><span class="cx"> 
</span><span class="cx"> } // namespace ImageControlsMac
</span></span></pre></div>
<a id="trunkSourceWebCoredommacImageControlsMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/dom/mac/ImageControlsMac.h (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/dom/mac/ImageControlsMac.h  2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebCore/dom/mac/ImageControlsMac.h     2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -39,6 +39,7 @@
</span><span class="cx"> bool hasControls(const HTMLElement&);
</span><span class="cx"> bool isImageControlsButtonElement(const Node&);
</span><span class="cx"> void createImageControls(HTMLElement&);
</span><ins>+bool handleEvent(HTMLElement&, Event&);
</ins><span class="cx"> 
</span><span class="cx"> #endif // ENABLE(SERVICE_CONTROLS)
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlHTMLButtonElementcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/HTMLButtonElement.cpp (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/HTMLButtonElement.cpp  2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebCore/html/HTMLButtonElement.cpp     2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -37,6 +37,10 @@
</span><span class="cx"> #include <wtf/SetForScope.h>
</span><span class="cx"> #include <wtf/StdLibExtras.h>
</span><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+#include "ImageControlsMac.h"
+#endif
+
</ins><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><span class="cx"> WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLButtonElement);
</span><span class="lines">@@ -128,6 +132,10 @@
</span><span class="cx"> 
</span><span class="cx"> void HTMLButtonElement::defaultEventHandler(Event& event)
</span><span class="cx"> {
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+    if (ImageControlsMac::handleEvent(*this, event))
+        return;
+#endif
</ins><span class="cx">     if (event.type() == eventNames().DOMActivateEvent && !isDisabledFormControl()) {
</span><span class="cx">         RefPtr<HTMLFormElement> protectedForm(form());
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorepageChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ChromeClient.h (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ChromeClient.h 2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebCore/page/ChromeClient.h    2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -532,6 +532,7 @@
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     virtual void handleSelectionServiceClick(FrameSelection&, const Vector<String>&, const IntPoint&) { }
</span><span class="cx">     virtual bool hasRelevantSelectionServices(bool /*isTextOnly*/) const { return false; }
</span><ins>+    virtual void handleImageServiceClick(const IntPoint&, Image&, bool /*isEditable*/) { }
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     virtual bool shouldDispatchFakeMouseMoveEvents() const { return true; }
</span></span></pre></div>
<a id="trunkSourceWebCorepageContextMenuControllercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/ContextMenuController.cpp (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/ContextMenuController.cpp      2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebCore/page/ContextMenuController.cpp 2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -147,21 +147,6 @@
</span><span class="cx">     showContextMenu(event);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-#if ENABLE(SERVICE_CONTROLS)
-
-static Image* imageFromImageElementNode(Node& node)
-{
-    auto* renderer = node.renderer();
-    if (!is<RenderImage>(renderer))
-        return nullptr;
-    auto* image = downcast<RenderImage>(*renderer).cachedImage();
-    if (!image || image->errorOccurred())
-        return nullptr;
-    return image->imageForRenderer(renderer);
-}
-
-#endif
-
</del><span class="cx"> std::unique_ptr<ContextMenu> ContextMenuController::maybeCreateContextMenu(Event& event, OptionSet<HitTestRequest::Type> hitType, ContextMenuContext::Type contextType)
</span><span class="cx"> {
</span><span class="cx">     if (!is<MouseEvent>(event))
</span><span class="lines">@@ -180,16 +165,6 @@
</span><span class="cx">         return nullptr;
</span><span class="cx"> 
</span><span class="cx">     m_context = ContextMenuContext(contextType, result);
</span><del>-
-#if ENABLE(SERVICE_CONTROLS)
-    if (ImageControlsMac::isImageControlsButtonElement(node)) {
-        if (auto* image = imageFromImageElementNode(*result.innerNonSharedNode()))
-            m_context.setControlledImage(image);
-
-        // FIXME: If we couldn't get the image then we shouldn't try to show the image controls menu for it.
-        return nullptr;
-    }
-#endif
</del><span class="cx">     
</span><span class="cx">     return makeUnique<ContextMenu>();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/ChangeLog    2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/ChangeLog       2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -1,3 +1,41 @@
</span><ins>+2021-12-08  Megan Gardner  <megan_gardner@apple.com>
+
+        Show correct content menu for images services chevron.
+        https://bugs.webkit.org/show_bug.cgi?id=233970
+
+        Reviewed by Tim Horton.
+
+        Add support for showing the correct context menu for image services.
+        Since this is internal only and can never be affected by web content, we bypass
+        the web content round trip and directly message the UIProcess about showing 
+        a context menu for images. And because it would be bizarre if the web content 
+        could prevent a menu from popping up on a button they have no control over.
+
+        * Shared/ContextMenuContextData.cpp:
+        (WebKit::ContextMenuContextData::ContextMenuContextData):
+        (WebKit::m_selectionIsEditable):
+        (WebKit::ContextMenuContextData::setImage):
+        (WebKit::ContextMenuContextData::controlledDataIsEditable const):
+        * Shared/ContextMenuContextData.h:
+        (WebKit::ContextMenuContextData::webHitTestResultData):
+        (WebKit::ContextMenuContextData::webHitTestResultData const):
+        * UIProcess/WebContextMenuProxy.cpp:
+        (WebKit::WebContextMenuProxy::show):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::contextMenuItemSelected):
+        * UIProcess/mac/WebContextMenuProxyMac.mm:
+        (WebKit::WebContextMenuProxyMac::getShareMenuItem):
+        (WebKit::WebContextMenuProxyMac::getContextMenuFromItems):
+        (WebKit::WebContextMenuProxyMac::useContextMenuItems):
+        * UIProcess/mac/WebPageProxyMac.mm:
+        (WebKit::WebPageProxy::handleContextMenuQuickLookImage):
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::handleImageServiceClick):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::handleImageServiceClick):
+
</ins><span class="cx"> 2021-12-08  Kyle Piddington  <kpiddington@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [MacCatalyst] Update header search paths for ANGLE Catalyst
</span></span></pre></div>
<a id="trunkSourceWebKitSharedContextMenuContextDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/ContextMenuContextData.cpp (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/ContextMenuContextData.cpp    2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/Shared/ContextMenuContextData.cpp       2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -51,7 +51,7 @@
</span><span class="cx"> #endif
</span><span class="cx">     , m_menuLocation(menuLocation)
</span><span class="cx">     , m_menuItems(menuItems)
</span><del>-    , m_webHitTestResultData(context.hitTestResult(), true)
</del><ins>+    , m_webHitTestResultData({ context.hitTestResult(), true })
</ins><span class="cx">     , m_selectedText(context.selectedText())
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     , m_selectionIsEditable(false)
</span><span class="lines">@@ -61,7 +61,22 @@
</span><span class="cx">     Image* image = context.controlledImage();
</span><span class="cx">     if (!image)
</span><span class="cx">         return;
</span><ins>+    
+    setImage(image);
+#endif
+}
</ins><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+ContextMenuContextData::ContextMenuContextData(const WebCore::IntPoint& menuLocation, WebCore::Image& image, bool isEditable)
+    : m_type(Type::ServicesMenu)
+    , m_menuLocation(menuLocation)
+    , m_selectionIsEditable(isEditable)
+{
+    setImage(&image);
+}
+
+void ContextMenuContextData::setImage(WebCore::Image* image)
+{
</ins><span class="cx">     // FIXME: figure out the rounding strategy for ShareableBitmap.
</span><span class="cx">     m_controlledImage = ShareableBitmap::createShareable(IntSize(image->size()), { });
</span><span class="cx">     auto graphicsContext = m_controlledImage->createGraphicsContext();
</span><span class="lines">@@ -68,8 +83,8 @@
</span><span class="cx">     if (!graphicsContext)
</span><span class="cx">         return;
</span><span class="cx">     graphicsContext->drawImage(*image, IntPoint());
</span><ins>+}
</ins><span class="cx"> #endif
</span><del>-}
</del><span class="cx"> 
</span><span class="cx"> void ContextMenuContextData::encode(IPC::Encoder& encoder) const
</span><span class="cx"> {
</span><span class="lines">@@ -129,12 +144,9 @@
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx"> bool ContextMenuContextData::controlledDataIsEditable() const
</span><span class="cx"> {
</span><del>-    if (!m_controlledSelectionData.isEmpty())
</del><ins>+    if (!m_controlledSelectionData.isEmpty() || m_controlledImage)
</ins><span class="cx">         return m_selectionIsEditable;
</span><span class="cx"> 
</span><del>-    if (m_controlledImage)
-        return m_webHitTestResultData.isContentEditable;
-
</del><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKitSharedContextMenuContextDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/Shared/ContextMenuContextData.h (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/Shared/ContextMenuContextData.h      2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/Shared/ContextMenuContextData.h 2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -51,8 +51,7 @@
</span><span class="cx">     const WebCore::IntPoint& menuLocation() const { return m_menuLocation; }
</span><span class="cx">     const Vector<WebKit::WebContextMenuItemData>& menuItems() const { return m_menuItems; }
</span><span class="cx"> 
</span><del>-    WebHitTestResultData& webHitTestResultData() { return m_webHitTestResultData; }
-    const WebHitTestResultData& webHitTestResultData() const { return m_webHitTestResultData; }
</del><ins>+    const std::optional<WebHitTestResultData>& webHitTestResultData() const { return m_webHitTestResultData; }
</ins><span class="cx">     const String& selectedText() const { return m_selectedText; }
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="lines">@@ -64,6 +63,8 @@
</span><span class="cx">         , m_selectionIsEditable(isEditable)
</span><span class="cx">     {
</span><span class="cx">     }
</span><ins>+    
+    ContextMenuContextData(const WebCore::IntPoint& menuLocation, WebCore::Image&, bool isEditable);
</ins><span class="cx"> 
</span><span class="cx">     ShareableBitmap* controlledImage() const { return m_controlledImage.get(); }
</span><span class="cx">     const Vector<uint8_t>& controlledSelectionData() const { return m_controlledSelectionData; }
</span><span class="lines">@@ -82,10 +83,12 @@
</span><span class="cx">     WebCore::IntPoint m_menuLocation;
</span><span class="cx">     Vector<WebKit::WebContextMenuItemData> m_menuItems;
</span><span class="cx"> 
</span><del>-    WebHitTestResultData m_webHitTestResultData;
</del><ins>+    std::optional<WebHitTestResultData> m_webHitTestResultData;
</ins><span class="cx">     String m_selectedText;
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><ins>+    void setImage(WebCore::Image*);
+    
</ins><span class="cx">     RefPtr<ShareableBitmap> m_controlledImage;
</span><span class="cx">     Vector<uint8_t> m_controlledSelectionData;
</span><span class="cx">     Vector<String> m_selectedTelephoneNumbers;
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebContextMenuProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp    2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/UIProcess/WebContextMenuProxy.cpp       2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -53,8 +53,10 @@
</span><span class="cx"> 
</span><span class="cx"> void WebContextMenuProxy::show()
</span><span class="cx"> {
</span><ins>+    ASSERT(m_context.webHitTestResultData());
+    
</ins><span class="cx">     m_contextMenuListener = WebContextMenuListenerProxy::create(*this);
</span><del>-    page()->contextMenuClient().getContextMenuFromProposedMenu(*page(), proposedItems(), *m_contextMenuListener, m_context.webHitTestResultData(), page()->process().transformHandlesToObjects(m_userData.object()).get());
</del><ins>+    page()->contextMenuClient().getContextMenuFromProposedMenu(*page(), proposedItems(), *m_contextMenuListener, m_context.webHitTestResultData().value(), page()->process().transformHandlesToObjects(m_userData.object()).get());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void WebContextMenuProxy::useContextMenuItems(Vector<Ref<WebContextMenuItem>>&& items)
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp   2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp      2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -6930,6 +6930,10 @@
</span><span class="cx">         String suggestedFilename;
</span><span class="cx">     };
</span><span class="cx">     std::optional<DownloadInfo> downloadInfo;
</span><ins>+    
+    ASSERT(m_activeContextMenuContextData.webHitTestResultData());
+    
+    auto hitTestData = m_activeContextMenuContextData.webHitTestResultData().value();
</ins><span class="cx"> 
</span><span class="cx">     switch (item.action()) {
</span><span class="cx"> #if PLATFORM(COCOA)
</span><span class="lines">@@ -6968,17 +6972,16 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     case ContextMenuItemTagDownloadImageToDisk:
</span><del>-        downloadInfo = {{ m_activeContextMenuContextData.webHitTestResultData().absoluteImageURL, { } }};
</del><ins>+        downloadInfo = { { hitTestData.absoluteImageURL, { } } };
</ins><span class="cx">         break;
</span><span class="cx"> 
</span><span class="cx">     case ContextMenuItemTagDownloadLinkToDisk: {
</span><del>-        auto& hitTestResult = m_activeContextMenuContextData.webHitTestResultData();
-        downloadInfo = {{ hitTestResult.absoluteLinkURL, hitTestResult.linkSuggestedFilename }};
</del><ins>+        downloadInfo = { { hitTestData.absoluteLinkURL, hitTestData.linkSuggestedFilename } };
</ins><span class="cx">         break;
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     case ContextMenuItemTagDownloadMediaToDisk:
</span><del>-        downloadInfo = {{ m_activeContextMenuContextData.webHitTestResultData().absoluteMediaURL, { } }};
</del><ins>+        downloadInfo = { { hitTestData.absoluteMediaURL, { } } };
</ins><span class="cx">         break;
</span><span class="cx"> 
</span><span class="cx">     case ContextMenuItemTagCheckSpellingWhileTyping:
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessmacWebContextMenuProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm      2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/UIProcess/mac/WebContextMenuProxyMac.mm 2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -309,7 +309,8 @@
</span><span class="cx"> 
</span><span class="cx"> void WebContextMenuProxyMac::getShareMenuItem(CompletionHandler<void(NSMenuItem *)>&& completionHandler)
</span><span class="cx"> {
</span><del>-    const WebHitTestResultData& hitTestData = m_context.webHitTestResultData();
</del><ins>+    ASSERT(m_context.webHitTestResultData());
+    auto hitTestData = m_context.webHitTestResultData().value();
</ins><span class="cx"> 
</span><span class="cx">     auto items = adoptNS([[NSMutableArray alloc] init]);
</span><span class="cx"> 
</span><span class="lines">@@ -533,8 +534,11 @@
</span><span class="cx">     }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><del>-    auto imageURL = URL { URL { }, m_context.webHitTestResultData().absoluteImageURL };
-    auto imageBitmap = m_context.webHitTestResultData().imageBitmap;
</del><ins>+    ASSERT(m_context.webHitTestResultData());
+    auto hitTestData = m_context.webHitTestResultData().value();
+    
+    auto imageURL = URL { URL { }, hitTestData.absoluteImageURL };
+    auto imageBitmap = hitTestData.imageBitmap;
</ins><span class="cx"> 
</span><span class="cx">     auto sparseMenuItems = retainPtr([NSPointerArray strongObjectsPointerArray]);
</span><span class="cx">     auto insertMenuItem = makeBlockPtr([protectedThis = Ref { *this }, weakPage = WeakPtr { page() }, imageURL = WTFMove(imageURL), imageBitmap = WTFMove(imageBitmap), shouldUpdateQuickLookItemTitle, quickLookItemToInsertIfNeeded = WTFMove(quickLookItemToInsertIfNeeded), completionHandler = WTFMove(completionHandler), itemsRemaining = filteredItems.size(), menu = WTFMove(menu), sparseMenuItems](NSMenuItem *item, NSUInteger index) mutable {
</span><span class="lines">@@ -715,8 +719,9 @@
</span><span class="cx">             menuFromProposedMenu(menu);
</span><span class="cx">             return;
</span><span class="cx">         }
</span><del>-
-        page()->contextMenuClient().menuFromProposedMenu(*page(), menu, m_context.webHitTestResultData(), m_userData.object(), WTFMove(menuFromProposedMenu));
</del><ins>+        
+        ASSERT(m_context.webHitTestResultData());
+        page()->contextMenuClient().menuFromProposedMenu(*page(), menu, m_context.webHitTestResultData().value(), m_userData.object(), WTFMove(menuFromProposedMenu));
</ins><span class="cx">     });
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessmacWebPageProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm     2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/UIProcess/mac/WebPageProxyMac.mm        2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -751,7 +751,9 @@
</span><span class="cx"> 
</span><span class="cx"> void WebPageProxy::handleContextMenuQuickLookImage(QuickLookPreviewActivity activity)
</span><span class="cx"> {
</span><del>-    auto& result = m_activeContextMenuContextData.webHitTestResultData();
</del><ins>+    ASSERT(m_activeContextMenuContextData.webHitTestResultData());
+    
+    auto result = m_activeContextMenuContextData.webHitTestResultData().value();
</ins><span class="cx">     if (!result.imageBitmap)
</span><span class="cx">         return;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebCoreSupportWebChromeClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp        2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.cpp   2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -1347,6 +1347,11 @@
</span><span class="cx">     return (isTextOnly && WebProcess::singleton().hasSelectionServices()) || WebProcess::singleton().hasRichContentServices();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebChromeClient::handleImageServiceClick(const IntPoint& point, Image& image, bool isEditable)
+{
+    m_page.handleImageServiceClick(point, image, isEditable);
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> bool WebChromeClient::shouldDispatchFakeMouseMoveEvents() const
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebCoreSupportWebChromeClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h  2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebChromeClient.h     2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -381,6 +381,7 @@
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&) final;
</span><span class="cx">     bool hasRelevantSelectionServices(bool isTextOnly) const final;
</span><ins>+    void handleImageServiceClick(const WebCore::IntPoint&, WebCore::Image&, bool isEditable) final;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     bool shouldDispatchFakeMouseMoveEvents() const final;
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h 2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h    2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -1203,6 +1203,7 @@
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS) || ENABLE(TELEPHONE_NUMBER_DETECTION)
</span><span class="cx">     void handleTelephoneNumberClick(const String& number, const WebCore::IntPoint&);
</span><span class="cx">     void handleSelectionServiceClick(WebCore::FrameSelection&, const Vector<String>& telephoneNumbers, const WebCore::IntPoint&);
</span><ins>+    void handleImageServiceClick(const WebCore::IntPoint&, WebCore::Image&, bool isEditable);
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     void didChangeScrollOffsetForFrame(WebCore::Frame*);
</span></span></pre></div>
<a id="trunkSourceWebKitWebProcessWebPagemacWebPageMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm (286761 => 286762)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm 2021-12-09 04:21:43 UTC (rev 286761)
+++ trunk/Source/WebKit/WebProcess/WebPage/mac/WebPageMac.mm    2021-12-09 05:27:01 UTC (rev 286762)
</span><span class="lines">@@ -828,6 +828,11 @@
</span><span class="cx">     send(Messages::WebPageProxy::ShowContextMenu(ContextMenuContextData(point, selectionDataVector, phoneNumbers, selection.selection().isContentEditable()), UserData()));
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void WebPage::handleImageServiceClick(const IntPoint& point, Image& image, bool isEditable)
+{
+    send(Messages::WebPageProxy::ShowContextMenu(ContextMenuContextData(point, image, isEditable), UserData()));
+}
+
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> String WebPage::platformUserAgent(const URL&) const
</span></span></pre>
</div>
</div>

</body>
</html>