<!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>[165856] trunk/Source/WebKit2</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/165856">165856</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-03-18 16:54:30 -0700 (Tue, 18 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Make image controls menu work in WK2
<rdar://problem/16294412> and https://bugs.webkit.org/show_bug.cgi?id=130424
Reviewed by Tim Horton.
* Platform/SharedMemory.h:
* Platform/mac/SharedMemoryMac.cpp:
(WebKit::SharedMemory::Handle::~Handle):
(WebKit::SharedMemory::Handle::clear):
* Platform/unix/SharedMemoryUnix.cpp:
(WebKit::SharedMemory::Handle::~Handle):
(WebKit::SharedMemory::Handle::clear):
* Shared/ContextMenuContextData.cpp:
(WebKit::ContextMenuContextData::ContextMenuContextData):
(WebKit::ContextMenuContextData::operator=):
(WebKit::ContextMenuContextData::encode):
(WebKit::ContextMenuContextData::decode):
* Shared/ContextMenuContextData.h:
(WebKit::ContextMenuContextData::controlledImageHandle):
* Shared/ShareableBitmap.cpp:
(WebKit::ShareableBitmap::Handle::clear):
* Shared/ShareableBitmap.h:
* UIProcess/WebContextMenuProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::internalShowContextMenu):
(WebKit::WebPageProxy::replaceControlledImage):
* UIProcess/WebPageProxy.h:
* UIProcess/efl/WebContextMenuProxyEfl.cpp:
(WebKit::WebContextMenuProxyEfl::showContextMenu):
* UIProcess/efl/WebContextMenuProxyEfl.h:
* UIProcess/gtk/WebContextMenuProxyGtk.cpp:
(WebKit::WebContextMenuProxyGtk::showContextMenu):
* UIProcess/gtk/WebContextMenuProxyGtk.h:
Add a sharing service context menu that lives side-by-side with the normal one:
* UIProcess/mac/WebContextMenuProxyMac.h:
* UIProcess/mac/WebContextMenuProxyMac.mm:
(+[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate]):
(-[WKSharingServicePickerDelegate setMenuProxy:WebKit::]):
(-[WKSharingServicePickerDelegate setPicker:]):
(-[WKSharingServicePickerDelegate sharingServicePicker:delegateForSharingService:]):
(-[WKSharingServicePickerDelegate sharingService:willShareItems:]):
(-[WKSharingServicePickerDelegate sharingService:didShareItems:]):
(-[WKSharingServicePickerDelegate sharingService:sourceFrameOnScreenForShareItem:]):
(-[WKSharingServicePickerDelegate sharingService:transitionImageForShareItem:contentRect:]):
(-[WKSharingServicePickerDelegate sharingService:sourceWindowForShareItems:sharingContentScope:]):
(WebKit::WebContextMenuProxyMac::contextMenuItemSelected):
(WebKit::WebContextMenuProxyMac::setupImageServicesMenu):
(WebKit::WebContextMenuProxyMac::clearImageServicesMenu):
(WebKit::WebContextMenuProxyMac::populate):
(WebKit::WebContextMenuProxyMac::showContextMenu):
(WebKit::WebContextMenuProxyMac::window):
(WebKit::WebContextMenuProxyMac::replaceControlledImage):
* WebProcess/WebPage/WebContextMenu.cpp:
(WebKit::WebContextMenu::show):
(WebKit::WebContextMenu::replaceControlledImage):
* WebProcess/WebPage/WebContextMenu.h:
Teach the WebProcess how to accept the replaced image.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::replaceControlledImage):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2PlatformSharedMemoryh">trunk/Source/WebKit2/Platform/SharedMemory.h</a></li>
<li><a href="#trunkSourceWebKit2PlatformmacSharedMemoryMaccpp">trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp</a></li>
<li><a href="#trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp">trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedContextMenuContextDatacpp">trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedContextMenuContextDatah">trunk/Source/WebKit2/Shared/ContextMenuContextData.h</a></li>
<li><a href="#trunkSourceWebKit2SharedShareableBitmapcpp">trunk/Source/WebKit2/Shared/ShareableBitmap.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedShareableBitmaph">trunk/Source/WebKit2/Shared/ShareableBitmap.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebContextMenuProxyh">trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxycpp">trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessWebPageProxyh">trunk/Source/WebKit2/UIProcess/WebPageProxy.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflcpp">trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflh">trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkcpp">trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp</a></li>
<li><a href="#trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkh">trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebContextMenuProxyMach">trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm">trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebContextMenucpp">trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebContextMenuh">trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagecpp">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPageh">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h</a></li>
<li><a href="#trunkSourceWebKit2WebProcessWebPageWebPagemessagesin">trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/ChangeLog        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -1,3 +1,76 @@
</span><ins>+2014-03-18 Brady Eidson <beidson@apple.com>
+
+ Make image controls menu work in WK2
+ <rdar://problem/16294412> and https://bugs.webkit.org/show_bug.cgi?id=130424
+
+ Reviewed by Tim Horton.
+
+ * Platform/SharedMemory.h:
+ * Platform/mac/SharedMemoryMac.cpp:
+ (WebKit::SharedMemory::Handle::~Handle):
+ (WebKit::SharedMemory::Handle::clear):
+
+ * Platform/unix/SharedMemoryUnix.cpp:
+ (WebKit::SharedMemory::Handle::~Handle):
+ (WebKit::SharedMemory::Handle::clear):
+
+ * Shared/ContextMenuContextData.cpp:
+ (WebKit::ContextMenuContextData::ContextMenuContextData):
+ (WebKit::ContextMenuContextData::operator=):
+ (WebKit::ContextMenuContextData::encode):
+ (WebKit::ContextMenuContextData::decode):
+ * Shared/ContextMenuContextData.h:
+ (WebKit::ContextMenuContextData::controlledImageHandle):
+
+ * Shared/ShareableBitmap.cpp:
+ (WebKit::ShareableBitmap::Handle::clear):
+ * Shared/ShareableBitmap.h:
+ * UIProcess/WebContextMenuProxy.h:
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::internalShowContextMenu):
+ (WebKit::WebPageProxy::replaceControlledImage):
+ * UIProcess/WebPageProxy.h:
+
+ * UIProcess/efl/WebContextMenuProxyEfl.cpp:
+ (WebKit::WebContextMenuProxyEfl::showContextMenu):
+ * UIProcess/efl/WebContextMenuProxyEfl.h:
+
+ * UIProcess/gtk/WebContextMenuProxyGtk.cpp:
+ (WebKit::WebContextMenuProxyGtk::showContextMenu):
+ * UIProcess/gtk/WebContextMenuProxyGtk.h:
+
+ Add a sharing service context menu that lives side-by-side with the normal one:
+ * UIProcess/mac/WebContextMenuProxyMac.h:
+ * UIProcess/mac/WebContextMenuProxyMac.mm:
+ (+[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate]):
+ (-[WKSharingServicePickerDelegate setMenuProxy:WebKit::]):
+ (-[WKSharingServicePickerDelegate setPicker:]):
+ (-[WKSharingServicePickerDelegate sharingServicePicker:delegateForSharingService:]):
+ (-[WKSharingServicePickerDelegate sharingService:willShareItems:]):
+ (-[WKSharingServicePickerDelegate sharingService:didShareItems:]):
+ (-[WKSharingServicePickerDelegate sharingService:sourceFrameOnScreenForShareItem:]):
+ (-[WKSharingServicePickerDelegate sharingService:transitionImageForShareItem:contentRect:]):
+ (-[WKSharingServicePickerDelegate sharingService:sourceWindowForShareItems:sharingContentScope:]):
+ (WebKit::WebContextMenuProxyMac::contextMenuItemSelected):
+ (WebKit::WebContextMenuProxyMac::setupImageServicesMenu):
+ (WebKit::WebContextMenuProxyMac::clearImageServicesMenu):
+ (WebKit::WebContextMenuProxyMac::populate):
+ (WebKit::WebContextMenuProxyMac::showContextMenu):
+ (WebKit::WebContextMenuProxyMac::window):
+ (WebKit::WebContextMenuProxyMac::replaceControlledImage):
+
+ * WebProcess/WebPage/WebContextMenu.cpp:
+ (WebKit::WebContextMenu::show):
+ (WebKit::WebContextMenu::replaceControlledImage):
+ * WebProcess/WebPage/WebContextMenu.h:
+
+ Teach the WebProcess how to accept the replaced image.
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::replaceControlledImage):
+ * WebProcess/WebPage/WebPage.h:
+ * WebProcess/WebPage/WebPage.messages.in:
+
</ins><span class="cx"> 2014-03-18 Anders Carlsson <andersca@apple.com>
</span><span class="cx">
</span><span class="cx"> Begin cleaning up KeyedDecoder and KeyedEncoder
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformSharedMemoryh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/SharedMemory.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -57,6 +57,8 @@
</span><span class="cx">
</span><span class="cx"> bool isNull() const;
</span><span class="cx">
</span><ins>+ void clear();
+
</ins><span class="cx"> void encode(IPC::ArgumentEncoder&) const;
</span><span class="cx"> static bool decode(IPC::ArgumentDecoder&, Handle&);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformmacSharedMemoryMaccpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Platform/mac/SharedMemoryMac.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -46,8 +46,7 @@
</span><span class="cx">
</span><span class="cx"> SharedMemory::Handle::~Handle()
</span><span class="cx"> {
</span><del>- if (m_port)
- mach_port_deallocate(mach_task_self(), m_port);
</del><ins>+ clear();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool SharedMemory::Handle::isNull() const
</span><span class="lines">@@ -55,6 +54,15 @@
</span><span class="cx"> return !m_port;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void SharedMemory::Handle::clear()
+{
+ if (m_port)
+ mach_port_deallocate(mach_task_self(), m_port);
+
+ m_port = MACH_PORT_NULL;
+ m_size = 0;
+}
+
</ins><span class="cx"> void SharedMemory::Handle::encode(IPC::ArgumentEncoder& encoder) const
</span><span class="cx"> {
</span><span class="cx"> encoder << static_cast<uint64_t>(m_size);
</span></span></pre></div>
<a id="trunkSourceWebKit2PlatformunixSharedMemoryUnixcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Platform/unix/SharedMemoryUnix.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -54,6 +54,11 @@
</span><span class="cx">
</span><span class="cx"> SharedMemory::Handle::~Handle()
</span><span class="cx"> {
</span><ins>+ clear();
+}
+
+void SharedMemory::Handle::clear()
+{
</ins><span class="cx"> if (!isNull())
</span><span class="cx"> closeWithRetry(m_fileDescriptor);
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedContextMenuContextDatacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -31,31 +31,55 @@
</span><span class="cx">
</span><span class="cx"> #include "WebCoreArgumentCoders.h"
</span><span class="cx"> #include <WebCore/ContextMenuContext.h>
</span><ins>+#include <WebCore/GraphicsContext.h>
</ins><span class="cx">
</span><span class="cx"> using namespace WebCore;
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><span class="cx"> ContextMenuContextData::ContextMenuContextData()
</span><del>-#if ENABLE(IMAGE_CONTROLS)
- : m_isImageControl(false)
-#endif
</del><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ContextMenuContextData::ContextMenuContextData(const ContextMenuContext& context)
</span><span class="cx"> : m_webHitTestResultData(WebHitTestResult::Data(context.hitTestResult()))
</span><ins>+{
</ins><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>- , m_isImageControl(context.controlledImage())
</del><ins>+ Image* image = context.controlledImage();
+ if (!image)
+ return;
+
+ RefPtr<ShareableBitmap> bitmap = ShareableBitmap::createShareable(image->size(), ShareableBitmap::SupportsAlpha);
+ bitmap->createGraphicsContext()->drawImage(image, ColorSpaceDeviceRGB, IntPoint());
+ bitmap->createHandle(m_controlledImageHandle);
</ins><span class="cx"> #endif
</span><ins>+}
+
+ContextMenuContextData::ContextMenuContextData(const ContextMenuContextData& other)
</ins><span class="cx"> {
</span><ins>+ *this = other;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+ContextMenuContextData& ContextMenuContextData::operator=(const ContextMenuContextData& other)
+{
+ m_webHitTestResultData = other.m_webHitTestResultData;
+#if ENABLE(IMAGE_CONTROLS)
+ m_controlledImageHandle.clear();
+
+ if (!other.m_controlledImageHandle.isNull()) {
+ RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(other.m_controlledImageHandle);
+ bitmap->createHandle(m_controlledImageHandle);
+ }
+#endif
+
+ return *this;
+}
+
</ins><span class="cx"> void ContextMenuContextData::encode(IPC::ArgumentEncoder& encoder) const
</span><span class="cx"> {
</span><span class="cx"> encoder << m_webHitTestResultData;
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>- encoder << m_isImageControl;
</del><ins>+ encoder << m_controlledImageHandle;
</ins><span class="cx"> #endif
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -65,7 +89,7 @@
</span><span class="cx"> return false;
</span><span class="cx">
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>- if (!decoder.decode(contextMenuContextData.m_isImageControl))
</del><ins>+ if (!decoder.decode(contextMenuContextData.m_controlledImageHandle))
</ins><span class="cx"> return false;
</span><span class="cx"> #endif
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedContextMenuContextDatah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ContextMenuContextData.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ContextMenuContextData.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ContextMenuContextData.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx">
</span><span class="cx"> #if ENABLE(CONTEXT_MENUS)
</span><span class="cx">
</span><ins>+#include "ShareableBitmap.h"
</ins><span class="cx"> #include "WebHitTestResult.h"
</span><span class="cx">
</span><span class="cx"> namespace IPC {
</span><span class="lines">@@ -46,11 +47,14 @@
</span><span class="cx"> public:
</span><span class="cx"> ContextMenuContextData();
</span><span class="cx"> ContextMenuContextData(const WebCore::ContextMenuContext&);
</span><ins>+
+ ContextMenuContextData(const ContextMenuContextData&);
+ ContextMenuContextData& operator=(const ContextMenuContextData&);
</ins><span class="cx">
</span><span class="cx"> const WebHitTestResult::Data& webHitTestResultData() const { return m_webHitTestResultData; }
</span><span class="cx">
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>- bool isImageControl() const { return m_isImageControl; }
</del><ins>+ const ShareableBitmap::Handle& controlledImageHandle() const { return m_controlledImageHandle; }
</ins><span class="cx"> #endif
</span><span class="cx">
</span><span class="cx"> void encode(IPC::ArgumentEncoder&) const;
</span><span class="lines">@@ -61,7 +65,7 @@
</span><span class="cx"> WebHitTestResult::Data m_webHitTestResultData;
</span><span class="cx">
</span><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>- bool m_isImageControl;
</del><ins>+ ShareableBitmap::Handle m_controlledImageHandle;
</ins><span class="cx"> #endif
</span><span class="cx"> };
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedShareableBitmapcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ShareableBitmap.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -57,6 +57,13 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void ShareableBitmap::Handle::clear()
+{
+ m_handle.clear();
+ m_size = IntSize();
+ m_flags = Flag::NoFlags;
+}
+
</ins><span class="cx"> PassRefPtr<ShareableBitmap> ShareableBitmap::create(const IntSize& size, Flags flags)
</span><span class="cx"> {
</span><span class="cx"> size_t numBytes = numBytesForSize(size);
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedShareableBitmaph"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/ShareableBitmap.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -63,6 +63,8 @@
</span><span class="cx">
</span><span class="cx"> bool isNull() const { return m_handle.isNull(); }
</span><span class="cx">
</span><ins>+ void clear();
+
</ins><span class="cx"> void encode(IPC::ArgumentEncoder&) const;
</span><span class="cx"> static bool decode(IPC::ArgumentDecoder&, Handle&);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebContextMenuProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/WebContextMenuProxy.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -36,13 +36,14 @@
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><ins>+class ContextMenuContextData;
</ins><span class="cx"> class WebContextMenuItemData;
</span><span class="cx">
</span><span class="cx"> class WebContextMenuProxy : public RefCounted<WebContextMenuProxy> {
</span><span class="cx"> public:
</span><span class="cx"> virtual ~WebContextMenuProxy();
</span><span class="cx">
</span><del>- virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>& items) = 0;
</del><ins>+ virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&, const ContextMenuContextData&) = 0;
</ins><span class="cx"> virtual void hideContextMenu() = 0;
</span><span class="cx">
</span><span class="cx"> protected:
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxycpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -3309,22 +3309,32 @@
</span><span class="cx"> // Unless this is an image control, give the PageContextMenuClient one last swipe at changing the menu.
</span><span class="cx"> Vector<WebContextMenuItemData> items;
</span><span class="cx"> bool useProposedItems = true;
</span><del>-
</del><ins>+ bool askClientToChangeMenu = true;
</ins><span class="cx"> #if ENABLE(IMAGE_CONTROLS)
</span><del>- if (!contextMenuContextData.isImageControl() && m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, contextMenuContextData.webHitTestResultData(), userData.get())) {
-#else
- if (m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, contextMenuContextData.webHitTestResultData(), userData.get())) {
</del><ins>+ if (!contextMenuContextData.controlledImageHandle().isNull())
+ askClientToChangeMenu = false;
</ins><span class="cx"> #endif
</span><ins>+
+ if (askClientToChangeMenu && m_contextMenuClient.getContextMenuFromProposedMenu(this, proposedItems, items, contextMenuContextData.webHitTestResultData(), userData.get()))
</ins><span class="cx"> useProposedItems = false;
</span><del>- }
</del><span class="cx">
</span><span class="cx"> const Vector<WebContextMenuItemData>& itemsToShow = useProposedItems ? proposedItems : items;
</span><span class="cx"> if (!m_contextMenuClient.showContextMenu(this, menuLocation, itemsToShow))
</span><del>- m_activeContextMenu->showContextMenu(menuLocation, itemsToShow);
-
</del><ins>+ m_activeContextMenu->showContextMenu(menuLocation, itemsToShow, contextMenuContextData);
+
</ins><span class="cx"> m_contextMenuClient.contextMenuDismissed(this);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebPageProxy::replaceControlledImage(PassRefPtr<ShareableBitmap> newBitmap)
+{
+ RefPtr<ShareableBitmap> bitmap = newBitmap;
+ ShareableBitmap::Handle bitmapHandle;
+ bitmap->createHandle(bitmapHandle);
+ m_process->send(Messages::WebPage::ReplaceControlledImage(bitmapHandle), m_pageID);
+}
+#endif
+
</ins><span class="cx"> void WebPageProxy::contextMenuItemSelected(const WebContextMenuItemData& item)
</span><span class="cx"> {
</span><span class="cx"> // Application custom items don't need to round-trip through to WebCore in the WebProcess.
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessWebPageProxyh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -925,6 +925,10 @@
</span><span class="cx">
</span><span class="cx"> void takeThumbnailSnapshot(ImageCallback::CallbackFunction);
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ void replaceControlledImage(PassRefPtr<ShareableBitmap>);
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx"> WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, const WebPageConfiguration&);
</span><span class="cx"> void platformInitialize();
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WebContextMenuProxyEfl::showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&)
</del><ins>+void WebContextMenuProxyEfl::showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&, const ContextMenuContextData&)
</ins><span class="cx"> {
</span><span class="cx"> notImplemented();
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcesseflWebContextMenuProxyEflh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/efl/WebContextMenuProxyEfl.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -48,7 +48,7 @@
</span><span class="cx">
</span><span class="cx"> ~WebContextMenuProxyEfl();
</span><span class="cx">
</span><del>- void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&);
</del><ins>+ void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&, const ContextMenuContextData&);
</ins><span class="cx"> void hideContextMenu();
</span><span class="cx">
</span><span class="cx"> private:
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -138,7 +138,7 @@
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WebContextMenuProxyGtk::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items)
</del><ins>+void WebContextMenuProxyGtk::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items, const ContextMenuContextData&)
</ins><span class="cx"> {
</span><span class="cx"> if (!items.isEmpty())
</span><span class="cx"> populate(items);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessgtkWebContextMenuProxyGtkh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -46,7 +46,7 @@
</span><span class="cx"> }
</span><span class="cx"> ~WebContextMenuProxyGtk();
</span><span class="cx">
</span><del>- virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&);
</del><ins>+ virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&, const ContextMenuContextData&);
</ins><span class="cx"> virtual void hideContextMenu();
</span><span class="cx">
</span><span class="cx"> void populate(Vector<WebCore::ContextMenuItem>&);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMach"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -32,10 +32,12 @@
</span><span class="cx"> #include <wtf/RetainPtr.h>
</span><span class="cx">
</span><span class="cx"> OBJC_CLASS NSPopUpButtonCell;
</span><ins>+OBJC_CLASS NSWindow;
</ins><span class="cx"> OBJC_CLASS WKView;
</span><span class="cx">
</span><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><ins>+class ShareableBitmap;
</ins><span class="cx"> class WebPageProxy;
</span><span class="cx">
</span><span class="cx"> class WebContextMenuProxyMac : public WebContextMenuProxy {
</span><span class="lines">@@ -46,17 +48,31 @@
</span><span class="cx"> }
</span><span class="cx"> ~WebContextMenuProxyMac();
</span><span class="cx">
</span><del>- virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&);
- virtual void hideContextMenu();
</del><ins>+ virtual void showContextMenu(const WebCore::IntPoint&, const Vector<WebContextMenuItemData>&, const ContextMenuContextData&) override;
+ virtual void hideContextMenu() override;
</ins><span class="cx">
</span><span class="cx"> void contextMenuItemSelected(const WebContextMenuItemData&);
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ void clearImageServicesMenu();
+ void replaceControlledImage(CGImageRef newImage);
+#endif
+
+ NSWindow *window() const;
+
</ins><span class="cx"> private:
</span><span class="cx"> WebContextMenuProxyMac(WKView*, WebPageProxy*);
</span><span class="cx">
</span><del>- void populate(const Vector<WebContextMenuItemData>&);
</del><ins>+ void populate(const Vector<WebContextMenuItemData>&, const ContextMenuContextData&);
</ins><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ void setupImageServicesMenu(ShareableBitmap&);
+#endif
+
</ins><span class="cx"> RetainPtr<NSPopUpButtonCell> m_popup;
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ RetainPtr<NSMenu> m_servicesMenu;
+#endif
</ins><span class="cx"> WKView* m_webView;
</span><span class="cx"> WebPageProxy* m_page;
</span><span class="cx"> };
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessmacWebContextMenuProxyMacmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/UIProcess/mac/WebContextMenuProxyMac.mm        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -29,12 +29,35 @@
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">
</span><span class="cx"> #import "PageClientImpl.h"
</span><ins>+#import "ShareableBitmap.h"
</ins><span class="cx"> #import "StringUtilities.h"
</span><span class="cx"> #import "WebContextMenuItemData.h"
</span><span class="cx"> #import "WKView.h"
</span><ins>+#import <WebCore/GraphicsContext.h>
</ins><span class="cx"> #import <WebCore/IntRect.h>
</span><ins>+#import <WebCore/NotImplemented.h>
</ins><span class="cx"> #import <WebKitSystemInterface.h>
</span><ins>+#import <wtf/RetainPtr.h>
</ins><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+#import <AppKit/NSSharingService.h>
+
+#if __has_include(<AppKit/NSSharingService_Private.h>)
+#import <AppKit/NSSharingService_Private.h>
+#else
+typedef enum {
+ NSSharingServicePickerStyleMenu = 0,
+ NSSharingServicePickerStyleRollover = 1,
+ NSSharingServicePickerStyleTextSelection = 2
+} NSSharingServicePickerStyle;
+#endif
+
+@interface NSSharingServicePicker (Details)
+@property NSSharingServicePickerStyle style;
+- (NSMenu *)menu;
+@end
+#endif
+
</ins><span class="cx"> using namespace WebCore;
</span><span class="cx">
</span><span class="cx"> @interface WKUserDataWrapper : NSObject {
</span><span class="lines">@@ -66,7 +89,7 @@
</span><span class="cx"> @interface WKMenuTarget : NSObject {
</span><span class="cx"> WebKit::WebContextMenuProxyMac* _menuProxy;
</span><span class="cx"> }
</span><del>-+ (WKMenuTarget*)sharedMenuTarget;
</del><ins>++ (WKMenuTarget *)sharedMenuTarget;
</ins><span class="cx"> - (WebKit::WebContextMenuProxyMac*)menuProxy;
</span><span class="cx"> - (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy;
</span><span class="cx"> - (void)forwardContextMenuAction:(id)sender;
</span><span class="lines">@@ -104,6 +127,67 @@
</span><span class="cx">
</span><span class="cx"> @end
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+@interface WKSharingServicePickerDelegate : NSObject <NSSharingServiceDelegate, NSSharingServicePickerDelegate> {
+ WebKit::WebContextMenuProxyMac* _menuProxy;
+ RetainPtr<NSSharingServicePicker> _picker;
+}
+
++ (WKSharingServicePickerDelegate *)sharedSharingServicePickerDelegate;
+- (WebKit::WebContextMenuProxyMac*)menuProxy;
+- (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy;
+- (void)setPicker:(NSSharingServicePicker *)picker;
+@end
+
+// FIXME: We probably need to hang on the picker itself until the context menu operation is done, and this object will probably do that.
+@implementation WKSharingServicePickerDelegate
++ (WKSharingServicePickerDelegate*)sharedSharingServicePickerDelegate
+{
+ static WKSharingServicePickerDelegate* delegate = [[WKSharingServicePickerDelegate alloc] init];
+ return delegate;
+}
+
+- (WebKit::WebContextMenuProxyMac*)menuProxy
+{
+ return _menuProxy;
+}
+
+- (void)setMenuProxy:(WebKit::WebContextMenuProxyMac*)menuProxy
+{
+ _menuProxy = menuProxy;
+}
+
+- (void)setPicker:(NSSharingServicePicker *)picker
+{
+ _picker = picker;
+}
+
+- (id <NSSharingServiceDelegate>)sharingServicePicker:(NSSharingServicePicker *)sharingServicePicker delegateForSharingService:(NSSharingService *)sharingService
+{
+ return self;
+}
+
+- (void)sharingService:(NSSharingService *)sharingService willShareItems:(NSArray *)items
+{
+ _menuProxy->clearImageServicesMenu();
+}
+
+- (void)sharingService:(NSSharingService *)sharingService didShareItems:(NSArray *)items
+{
+ RetainPtr<CGImageSourceRef> source = adoptCF(CGImageSourceCreateWithData((CFDataRef)[items objectAtIndex:0], NULL));
+ RetainPtr<CGImageRef> image = adoptCF(CGImageSourceCreateImageAtIndex(source.get(), 0, NULL));
+ _menuProxy->replaceControlledImage(image.get());
+}
+
+- (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
+{
+ return _menuProxy->window();
+}
+
+@end
+
+#endif
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><span class="cx"> WebContextMenuProxyMac::WebContextMenuProxyMac(WKView* webView, WebPageProxy* page)
</span><span class="lines">@@ -120,6 +204,10 @@
</span><span class="cx">
</span><span class="cx"> void WebContextMenuProxyMac::contextMenuItemSelected(const WebContextMenuItemData& item)
</span><span class="cx"> {
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ clearImageServicesMenu();
+#endif
+
</ins><span class="cx"> m_page->contextMenuItemSelected(item);
</span><span class="cx"> }
</span><span class="cx">
</span><span class="lines">@@ -185,8 +273,36 @@
</span><span class="cx"> return result;
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WebContextMenuProxyMac::populate(const Vector<WebContextMenuItemData>& items)
</del><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebContextMenuProxyMac::setupImageServicesMenu(ShareableBitmap& image)
</ins><span class="cx"> {
</span><ins>+ RetainPtr<CGImageRef> cgImage = image.makeCGImage();
+ RetainPtr<NSImage> nsImage = adoptNS([[NSImage alloc] initWithCGImage:cgImage.get() size:image.size()]);
+
+ RetainPtr<NSSharingServicePicker> picker = adoptNS([[NSSharingServicePicker alloc] initWithItems:@[ nsImage.get() ]]);
+ [picker setStyle:NSSharingServicePickerStyleRollover];
+ [picker setDelegate:[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate]];
+ [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setPicker:picker.get()];
+
+ m_servicesMenu = [picker menu];
+}
+
+void WebContextMenuProxyMac::clearImageServicesMenu()
+{
+ [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setPicker:nullptr];
+ m_servicesMenu = nullptr;
+}
+#endif
+
+void WebContextMenuProxyMac::populate(const Vector<WebContextMenuItemData>& items, const ContextMenuContextData& context)
+{
+#if ENABLE(IMAGE_CONTROLS)
+ if (RefPtr<ShareableBitmap> image = ShareableBitmap::create(context.controlledImageHandle())) {
+ setupImageServicesMenu(*image);
+ return;
+ }
+#endif
+
</ins><span class="cx"> if (m_popup)
</span><span class="cx"> [m_popup removeAllItems];
</span><span class="cx"> else {
</span><span class="lines">@@ -199,22 +315,38 @@
</span><span class="cx"> populateNSMenu(menu, nsMenuItemVector(items));
</span><span class="cx"> }
</span><span class="cx">
</span><del>-void WebContextMenuProxyMac::showContextMenu(const IntPoint& menuLocation, const Vector<WebContextMenuItemData>& items)
</del><ins>+void WebContextMenuProxyMac::showContextMenu(const IntPoint& menuLocation, const Vector<WebContextMenuItemData>& items, const ContextMenuContextData& context)
</ins><span class="cx"> {
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ if (items.isEmpty() && context.controlledImageHandle().isNull())
+ return;
+#else
</ins><span class="cx"> if (items.isEmpty())
</span><span class="cx"> return;
</span><del>-
- populate(items);
</del><ins>+#endif
+
+ populate(items, context);
+
</ins><span class="cx"> [[WKMenuTarget sharedMenuTarget] setMenuProxy:this];
</span><del>-
</del><ins>+
</ins><span class="cx"> NSRect menuRect = NSMakeRect(menuLocation.x(), menuLocation.y(), 0, 0);
</span><del>-
</del><ins>+
+#if ENABLE(IMAGE_CONTROLS)
+ if (!context.controlledImageHandle().isNull())
+ [[WKSharingServicePickerDelegate sharedSharingServicePickerDelegate] setMenuProxy:this];
+
+ if (!m_servicesMenu)
+ [m_popup attachPopUpWithFrame:menuRect inView:m_webView];
+
+ NSMenu *menu = m_servicesMenu ? m_servicesMenu.get() : [m_popup menu];
+#else
</ins><span class="cx"> [m_popup attachPopUpWithFrame:menuRect inView:m_webView];
</span><span class="cx">
</span><del>- NSMenu* menu = [m_popup menu];
</del><ins>+ NSMenu *menu = [m_popup menu];
+#endif
</ins><span class="cx">
</span><span class="cx"> // These values were borrowed from AppKit to match their placement of the menu.
</span><del>- NSRect titleFrame = [m_popup titleRectForBounds:menuRect];
</del><ins>+ NSRect titleFrame = [m_popup titleRectForBounds:menuRect];
</ins><span class="cx"> if (titleFrame.size.width <= 0 || titleFrame.size.height <= 0)
</span><span class="cx"> titleFrame = menuRect;
</span><span class="cx"> float vertOffset = roundf((NSMaxY(menuRect) - NSMaxY(titleFrame)) + NSHeight(titleFrame));
</span><span class="lines">@@ -228,7 +360,7 @@
</span><span class="cx">
</span><span class="cx"> WKPopupContextMenu(menu, location);
</span><span class="cx">
</span><del>- [m_popup dismissPopUp];
</del><ins>+ hideContextMenu();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> void WebContextMenuProxyMac::hideContextMenu()
</span><span class="lines">@@ -236,6 +368,22 @@
</span><span class="cx"> [m_popup dismissPopUp];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+NSWindow *WebContextMenuProxyMac::window() const
+{
+ return [m_webView window];
+}
+
+#if ENABLE(IMAGE_CONTROLS)
+void WebContextMenuProxyMac::replaceControlledImage(CGImageRef newImage)
+{
+ FloatSize newImageSize(CGImageGetWidth(newImage), CGImageGetHeight(newImage));
+ RefPtr<ShareableBitmap> newBitmap = ShareableBitmap::createShareable(expandedIntSize(newImageSize), ShareableBitmap::SupportsAlpha);
+ newBitmap->createGraphicsContext()->drawNativeImage(newImage, newImageSize, ColorSpaceDeviceRGB, FloatRect(FloatPoint(), newImageSize), FloatRect(FloatPoint(), newImageSize));
+
+ m_page->replaceControlledImage(newBitmap.release());
+}
+#endif
+
</ins><span class="cx"> } // namespace WebKit
</span><span class="cx">
</span><span class="cx"> #endif // PLATFORM(MAC)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebContextMenucpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -54,9 +54,6 @@
</span><span class="cx"> void WebContextMenu::show()
</span><span class="cx"> {
</span><span class="cx"> ContextMenuController& controller = m_page->corePage()->contextMenuController();
</span><del>- ContextMenu* menu = controller.contextMenu();
- if (!menu)
- return;
</del><span class="cx"> Frame* frame = controller.hitTestResult().innerNodeFrame();
</span><span class="cx"> if (!frame)
</span><span class="cx"> return;
</span><span class="lines">@@ -80,6 +77,13 @@
</span><span class="cx"> m_page->corePage()->contextMenuController().contextMenuItemSelected(&coreItem);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebContextMenu::replaceControlledImage(PassRefPtr<Image> newImage)
+{
+ m_page->corePage()->contextMenuController().replaceControlledImage(newImage);
+}
+#endif
+
</ins><span class="cx"> void WebContextMenu::menuItemsWithUserData(Vector<WebContextMenuItemData> &menuItems, RefPtr<API::Object>& userData) const
</span><span class="cx"> {
</span><span class="cx"> ContextMenuController& controller = m_page->corePage()->contextMenuController();
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebContextMenuh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebContextMenu.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -28,8 +28,13 @@
</span><span class="cx"> #include <wtf/PassRefPtr.h>
</span><span class="cx"> #include <wtf/RefCounted.h>
</span><span class="cx">
</span><ins>+namespace WebCore {
+class Image;
+}
+
</ins><span class="cx"> namespace WebKit {
</span><span class="cx">
</span><ins>+class ShareableBitmap;
</ins><span class="cx"> class WebPage;
</span><span class="cx">
</span><span class="cx"> class WebContextMenu : public RefCounted<WebContextMenu> {
</span><span class="lines">@@ -45,6 +50,10 @@
</span><span class="cx"> void itemSelected(const WebContextMenuItemData&);
</span><span class="cx"> Vector<WebContextMenuItemData> items() const;
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ void replaceControlledImage(PassRefPtr<WebCore::Image>);
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx"> WebContextMenu(WebPage*);
</span><span class="cx"> void menuItemsWithUserData(Vector<WebContextMenuItemData>&, RefPtr<API::Object>&) const;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -3088,6 +3088,15 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+void WebPage::replaceControlledImage(const ShareableBitmap::Handle& bitmapHandle)
+{
+ RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(bitmapHandle);
+ if (bitmap)
+ m_contextMenu->replaceControlledImage(bitmap->createImage());
+}
+#endif
+
</ins><span class="cx"> void WebPage::replaceSelectionWithText(Frame* frame, const String& text)
</span><span class="cx"> {
</span><span class="cx"> bool selectReplacement = true;
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -742,6 +742,10 @@
</span><span class="cx">
</span><span class="cx"> void getBytecodeProfile(uint64_t callbackID);
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ void replaceControlledImage(const ShareableBitmap::Handle&);
+#endif
+
</ins><span class="cx"> private:
</span><span class="cx"> WebPage(uint64_t pageID, const WebPageCreationParameters&);
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagemessagesin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in (165855 => 165856)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-03-18 23:53:49 UTC (rev 165855)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.messages.in        2014-03-18 23:54:30 UTC (rev 165856)
</span><span class="lines">@@ -343,4 +343,7 @@
</span><span class="cx">
</span><span class="cx"> TakeThumbnailSnapshot(uint64_t callbackID)
</span><span class="cx">
</span><ins>+#if ENABLE(IMAGE_CONTROLS)
+ ReplaceControlledImage(WebKit::ShareableBitmap::Handle newBitmapHandle)
+#endif
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
</body>
</html>