Implement NSSharingServiceDelegate method "transitionImageForShareItem"
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 May 2014 20:12:14 +0000 (20:12 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 May 2014 20:12:14 +0000 (20:12 +0000)
<rdar://problem/16878020> 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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@168859 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/Misc/WebSharingServicePickerController.mm
Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.h
Source/WebKit/mac/WebCoreSupport/WebContextMenuClient.mm

index 0787dc0..fdbf2f2 100644 (file)
@@ -1,3 +1,13 @@
+2014-05-14  Brady Eidson  <beidson@apple.com>
+
+        Implement NSSharingServiceDelegate method "transitionImageForShareItem"
+        <rdar://problem/16878020> and https://bugs.webkit.org/show_bug.cgi?id=132911
+
+        Reviewed by Tim Horton.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2014-05-14  Alex Christensen  <achristensen@webkit.org>
 
         Another unreviewed build fix.
index 0888cf3..854fd18 100644 (file)
@@ -3270,7 +3270,13 @@ __ZNK7WebCore9FrameView34setWantsLayerForBottomOverHangAreaEb
 #endif
 
 #if ENABLE(SERVICE_CONTROLS)
+__ZN7WebCore11ImageBufferC1ERKNS_9FloatSizeEfNS_10ColorSpaceENS_13RenderingModeERb
+__ZN7WebCore11ImageBufferD1Ev
 __ZN7WebCore25attributedStringFromRangeERNS_5RangeE
+__ZN7WebCore5Range6createERNS_8DocumentERKNS_8PositionES5_
+__ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEENS0_10AnchorTypeE
+__ZNK7WebCore11ImageBuffer7contextEv
+__ZNK7WebCore11ImageBuffer9copyImageENS_16BackingStoreCopyENS_13ScaleBehaviorE
 __ZNK7WebCore16VisibleSelection10firstRangeEv
 #endif
 
index 6c75c17..ae5808b 100644 (file)
                227777601345DEA9008EA455 /* InspectorForwarding.h in Headers */ = {isa = PBXBuildFile; fileRef = 2277775F1345DEA9008EA455 /* InspectorForwarding.h */; settings = {ATTRIBUTES = (Private, ); }; };
                228C284510D82500009D0D0E /* ScriptWrappable.h in Headers */ = {isa = PBXBuildFile; fileRef = 228C284410D82500009D0D0E /* ScriptWrappable.h */; settings = {ATTRIBUTES = (Private, ); }; };
                2292B27C1356669400CF11EF /* ImageBufferDataCG.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2292B27B1356669400CF11EF /* ImageBufferDataCG.cpp */; };
-               22BD9F7F1353625C009BD102 /* ImageBufferData.h in Headers */ = {isa = PBXBuildFile; fileRef = 22BD9F7D1353625C009BD102 /* ImageBufferData.h */; };
-               22BD9F81135364FE009BD102 /* ImageBufferDataCG.h in Headers */ = {isa = PBXBuildFile; fileRef = 22BD9F80135364FE009BD102 /* ImageBufferDataCG.h */; };
+               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, ); }; };
                24D9129113CA951E00D21915 /* JSSVGAltGlyphDefElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 24D9128F13CA951E00D21915 /* JSSVGAltGlyphDefElement.cpp */; };
                24D9129213CA951E00D21915 /* JSSVGAltGlyphDefElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 24D9129013CA951E00D21915 /* JSSVGAltGlyphDefElement.h */; };
                24D9129513CA956100D21915 /* JSSVGAltGlyphItemElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 24D9129313CA956100D21915 /* JSSVGAltGlyphItemElement.cpp */; };
index 4434c83..7a4af05 100644 (file)
@@ -1,5 +1,21 @@
 2014-05-14  Brady Eidson  <beidson@apple.com>
 
+        Implement NSSharingServiceDelegate method "transitionImageForShareItem"
+        <rdar://problem/16878020> 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  <beidson@apple.com>
+
         sourceFrameOnScreenForShareItem: can be off by a pixel
         <rdar://problem/16878020> and https://bugs.webkit.org/show_bug.cgi?id=132911
 
index 8b6b5d7..d21bc38 100644 (file)
@@ -212,6 +212,14 @@ using namespace WebCore;
     return _menuClient->screenRectForHitTestNode();
 }
 
+- (NSImage *)sharingService:(NSSharingService *)sharingService transitionImageForShareItem:(id <NSPasteboardWriting>)item contentRect:(NSRect *)contentRect
+{
+    if (!_menuClient)
+        return nil;
+
+    return _menuClient->renderedImageForControlledImage();
+}
+
 - (NSWindow *)sharingService:(NSSharingService *)sharingService sourceWindowForShareItems:(NSArray *)items sharingContentScope:(NSSharingContentScope *)sharingContentScope
 {
     return [_menuClient->webView() window];
index 3c2349e..170b4d5 100644 (file)
@@ -59,6 +59,7 @@ public:
 
 #if ENABLE(SERVICE_CONTROLS)
     void clearSharingServicePickerController();
+    NSImage *renderedImageForControlledImage() const;
 #endif
 
     WebView *webView() { return m_webView; }
index 4380184..88731ff 100644 (file)
@@ -49,6 +49,8 @@
 #import <WebCore/Document.h>
 #import <WebCore/Frame.h>
 #import <WebCore/FrameView.h>
+#import <WebCore/GraphicsContext.h>
+#import <WebCore/ImageBuffer.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/Page.h>
 #import <WebCore/RenderBox.h>
@@ -413,6 +415,51 @@ NSRect WebContextMenuClient::screenRectForHitTestNode() const
     return frameView->contentsToScreen(intRect);
 }
 
+#if ENABLE(SERVICE_CONTROLS)
+NSImage *WebContextMenuClient::renderedImageForControlledImage() const
+{
+    Page* page = [m_webView page];
+    if (!page)
+        return nil;
+
+    Node* node = page->contextMenuController().context().hitTestResult().innerNode();
+    if (!node)
+        return nil;
+
+    FrameView* frameView = node->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<ImageBuffer> buffer = ImageBuffer::create(rect.size());
+    if (!buffer)
+        return nil;
+
+    VisibleSelection oldSelection = frameView->frame().selection().selection();
+    RefPtr<Range> range = Range::create(node->document(), Position(node, Position::PositionIsBeforeAnchor), Position(node, Position::PositionIsAfterAnchor));
+    frameView->frame().selection().setSelection(VisibleSelection(range.get()), FrameSelection::DoNotSetFocus);
+
+    PaintBehavior oldPaintBehavior = frameView->paintBehavior();
+    frameView->setPaintBehavior(PaintBehaviorSelectionOnly);
+
+    buffer->context()->translate(-toFloatSize(rect.location()));
+    frameView->paintContents(buffer->context(), roundedIntRect(rect));
+
+    frameView->frame().selection().setSelection(oldSelection);
+    frameView->setPaintBehavior(oldPaintBehavior);
+
+    RefPtr<Image> image = buffer->copyImage(DontCopyBackingStore);
+    return [[image->getNSImage() retain] autorelease];
+}
+#endif
+
+
 NSMenu *WebContextMenuClient::contextMenuForEvent(NSEvent *event, NSView *view)
 {
     Page* page = [m_webView page];