<!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>[168859] 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/168859">168859</a></dd>
<dt>Author</dt> <dd>beidson@apple.com</dd>
<dt>Date</dt> <dd>2014-05-14 13:12:14 -0700 (Wed, 14 May 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Implement NSSharingServiceDelegate method &quot;transitionImageForShareItem&quot;
&lt;rdar://problem/16878020&gt; and https://bugs.webkit.org/show_bug.cgi?id=132911

Reviewed by Tim Horton.

Source/WebCore:
* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:

Source/WebKit/mac:
* Misc/WebSharingServicePickerController.mm:
(-[WebSharingServicePickerController sharingService:transitionImageForShareItem:contentRect:]):

* WebCoreSupport/WebContextMenuClient.h:
* WebCoreSupport/WebContextMenuClient.mm:
(WebContextMenuClient::renderedImageForControlledImage): Paint the entire content rect for the controlled image
  into an ImageBuffer, then return the resulting NSImage. This only paints the image itself and not any
  overlapping content by setting the selection and appropriate painting mode.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebKitmacChangeLog">trunk/Source/WebKit/mac/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitmacMiscWebSharingServicePickerControllermm">trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebContextMenuClienth">trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h</a></li>
<li><a href="#trunkSourceWebKitmacWebCoreSupportWebContextMenuClientmm">trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (168858 => 168859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-05-14 20:11:12 UTC (rev 168858)
+++ trunk/Source/WebCore/ChangeLog        2014-05-14 20:12:14 UTC (rev 168859)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2014-05-14  Brady Eidson  &lt;beidson@apple.com&gt;
+
+        Implement NSSharingServiceDelegate method &quot;transitionImageForShareItem&quot;
+        &lt;rdar://problem/16878020&gt; and https://bugs.webkit.org/show_bug.cgi?id=132911
+
+        Reviewed by Tim Horton.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+
</ins><span class="cx"> 2014-05-14  Alex Christensen  &lt;achristensen@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Another unreviewed build fix.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (168858 => 168859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2014-05-14 20:11:12 UTC (rev 168858)
+++ trunk/Source/WebCore/WebCore.exp.in        2014-05-14 20:12:14 UTC (rev 168859)
</span><span class="lines">@@ -3270,7 +3270,13 @@
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><ins>+__ZN7WebCore11ImageBufferC1ERKNS_9FloatSizeEfNS_10ColorSpaceENS_13RenderingModeERb
+__ZN7WebCore11ImageBufferD1Ev
</ins><span class="cx"> __ZN7WebCore25attributedStringFromRangeERNS_5RangeE
</span><ins>+__ZN7WebCore5Range6createERNS_8DocumentERKNS_8PositionES5_
+__ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEENS0_10AnchorTypeE
+__ZNK7WebCore11ImageBuffer7contextEv
+__ZNK7WebCore11ImageBuffer9copyImageENS_16BackingStoreCopyENS_13ScaleBehaviorE
</ins><span class="cx"> __ZNK7WebCore16VisibleSelection10firstRangeEv
</span><span class="cx"> #endif
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (168858 => 168859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-05-14 20:11:12 UTC (rev 168858)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-05-14 20:12:14 UTC (rev 168859)
</span><span class="lines">@@ -967,8 +967,8 @@
</span><span class="cx">                 227777601345DEA9008EA455 /* InspectorForwarding.h in Headers */ = {isa = PBXBuildFile; fileRef = 2277775F1345DEA9008EA455 /* InspectorForwarding.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 228C284510D82500009D0D0E /* ScriptWrappable.h in Headers */ = {isa = PBXBuildFile; fileRef = 228C284410D82500009D0D0E /* ScriptWrappable.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 2292B27C1356669400CF11EF /* ImageBufferDataCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2292B27B1356669400CF11EF /* ImageBufferDataCG.cpp */; };
</span><del>-                22BD9F7F1353625C009BD102 /* ImageBufferData.h in Headers */ = {isa = PBXBuildFile; fileRef = 22BD9F7D1353625C009BD102 /* ImageBufferData.h */; };
-                22BD9F81135364FE009BD102 /* ImageBufferDataCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 22BD9F80135364FE009BD102 /* ImageBufferDataCG.h */; };
</del><ins>+                22BD9F7F1353625C009BD102 /* ImageBufferData.h in Headers */ = {isa = PBXBuildFile; fileRef = 22BD9F7D1353625C009BD102 /* ImageBufferData.h */; settings = {ATTRIBUTES = (Private, ); }; };
+                22BD9F81135364FE009BD102 /* ImageBufferDataCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 22BD9F80135364FE009BD102 /* ImageBufferDataCG.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 24D9129113CA951E00D21915 /* JSSVGAltGlyphDefElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 24D9128F13CA951E00D21915 /* JSSVGAltGlyphDefElement.cpp */; };
</span><span class="cx">                 24D9129213CA951E00D21915 /* JSSVGAltGlyphDefElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 24D9129013CA951E00D21915 /* JSSVGAltGlyphDefElement.h */; };
</span><span class="cx">                 24D9129513CA956100D21915 /* JSSVGAltGlyphItemElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 24D9129313CA956100D21915 /* JSSVGAltGlyphItemElement.cpp */; };
</span></span></pre></div>
<a id="trunkSourceWebKitmacChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/ChangeLog (168858 => 168859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/ChangeLog        2014-05-14 20:11:12 UTC (rev 168858)
+++ trunk/Source/WebKit/mac/ChangeLog        2014-05-14 20:12:14 UTC (rev 168859)
</span><span class="lines">@@ -1,5 +1,21 @@
</span><span class="cx"> 2014-05-14  Brady Eidson  &lt;beidson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Implement NSSharingServiceDelegate method &quot;transitionImageForShareItem&quot;
+        &lt;rdar://problem/16878020&gt; and https://bugs.webkit.org/show_bug.cgi?id=132911
+
+        Reviewed by Tim Horton.
+
+        * Misc/WebSharingServicePickerController.mm:
+        (-[WebSharingServicePickerController sharingService:transitionImageForShareItem:contentRect:]):
+
+        * WebCoreSupport/WebContextMenuClient.h:
+        * WebCoreSupport/WebContextMenuClient.mm:
+        (WebContextMenuClient::renderedImageForControlledImage): Paint the entire content rect for the controlled image
+          into an ImageBuffer, then return the resulting NSImage. This only paints the image itself and not any
+          overlapping content by setting the selection and appropriate painting mode.
+
+2014-05-14  Brady Eidson  &lt;beidson@apple.com&gt;
+
</ins><span class="cx">         sourceFrameOnScreenForShareItem: can be off by a pixel
</span><span class="cx">         &lt;rdar://problem/16878020&gt; and https://bugs.webkit.org/show_bug.cgi?id=132911
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebKitmacMiscWebSharingServicePickerControllermm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm (168858 => 168859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm        2014-05-14 20:11:12 UTC (rev 168858)
+++ trunk/Source/WebKit/mac/Misc/WebSharingServicePickerController.mm        2014-05-14 20:12:14 UTC (rev 168859)
</span><span class="lines">@@ -212,6 +212,14 @@
</span><span class="cx">     return _menuClient-&gt;screenRectForHitTestNode();
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+- (NSImage *)sharingService:(NSSharingService *)sharingService transitionImageForShareItem:(id &lt;NSPasteboardWriting&gt;)item contentRect:(NSRect *)contentRect
+{
+    if (!_menuClient)
+        return nil;
+
+    return _menuClient-&gt;renderedImageForControlledImage();
+}
+
</ins><span class="cx"> - (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
</span><span class="cx"> {
</span><span class="cx">     return [_menuClient-&gt;webView() window];
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebContextMenuClienth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h (168858 => 168859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h        2014-05-14 20:11:12 UTC (rev 168858)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h        2014-05-14 20:12:14 UTC (rev 168859)
</span><span class="lines">@@ -59,6 +59,7 @@
</span><span class="cx"> 
</span><span class="cx"> #if ENABLE(SERVICE_CONTROLS)
</span><span class="cx">     void clearSharingServicePickerController();
</span><ins>+    NSImage *renderedImageForControlledImage() const;
</ins><span class="cx"> #endif
</span><span class="cx"> 
</span><span class="cx">     WebView *webView() { return m_webView; }
</span></span></pre></div>
<a id="trunkSourceWebKitmacWebCoreSupportWebContextMenuClientmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm (168858 => 168859)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm        2014-05-14 20:11:12 UTC (rev 168858)
+++ trunk/Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm        2014-05-14 20:12:14 UTC (rev 168859)
</span><span class="lines">@@ -49,6 +49,8 @@
</span><span class="cx"> #import &lt;WebCore/Document.h&gt;
</span><span class="cx"> #import &lt;WebCore/Frame.h&gt;
</span><span class="cx"> #import &lt;WebCore/FrameView.h&gt;
</span><ins>+#import &lt;WebCore/GraphicsContext.h&gt;
+#import &lt;WebCore/ImageBuffer.h&gt;
</ins><span class="cx"> #import &lt;WebCore/LocalizedStrings.h&gt;
</span><span class="cx"> #import &lt;WebCore/Page.h&gt;
</span><span class="cx"> #import &lt;WebCore/RenderBox.h&gt;
</span><span class="lines">@@ -413,6 +415,51 @@
</span><span class="cx">     return frameView-&gt;contentsToScreen(intRect);
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#if ENABLE(SERVICE_CONTROLS)
+NSImage *WebContextMenuClient::renderedImageForControlledImage() const
+{
+    Page* page = [m_webView page];
+    if (!page)
+        return nil;
+
+    Node* node = page-&gt;contextMenuController().context().hitTestResult().innerNode();
+    if (!node)
+        return nil;
+
+    FrameView* frameView = node-&gt;document().view();
+    if (!frameView) {
+        // This method shouldn't be called in cases where the controlled node isn't in a rendered view.
+        ASSERT_NOT_REACHED();
+        return nil;
+    }
+
+    FloatRect rect;
+    if (!clientFloatRectForNode(*node, rect))
+        return nil;
+
+    std::unique_ptr&lt;ImageBuffer&gt; buffer = ImageBuffer::create(rect.size());
+    if (!buffer)
+        return nil;
+
+    VisibleSelection oldSelection = frameView-&gt;frame().selection().selection();
+    RefPtr&lt;Range&gt; range = Range::create(node-&gt;document(), Position(node, Position::PositionIsBeforeAnchor), Position(node, Position::PositionIsAfterAnchor));
+    frameView-&gt;frame().selection().setSelection(VisibleSelection(range.get()), FrameSelection::DoNotSetFocus);
+
+    PaintBehavior oldPaintBehavior = frameView-&gt;paintBehavior();
+    frameView-&gt;setPaintBehavior(PaintBehaviorSelectionOnly);
+
+    buffer-&gt;context()-&gt;translate(-toFloatSize(rect.location()));
+    frameView-&gt;paintContents(buffer-&gt;context(), roundedIntRect(rect));
+
+    frameView-&gt;frame().selection().setSelection(oldSelection);
+    frameView-&gt;setPaintBehavior(oldPaintBehavior);
+
+    RefPtr&lt;Image&gt; image = buffer-&gt;copyImage(DontCopyBackingStore);
+    return [[image-&gt;getNSImage() retain] autorelease];
+}
+#endif
+
+
</ins><span class="cx"> NSMenu *WebContextMenuClient::contextMenuForEvent(NSEvent *event, NSView *view)
</span><span class="cx"> {
</span><span class="cx">     Page* page = [m_webView page];
</span></span></pre>
</div>
</div>

</body>
</html>