<!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>[171057] 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/171057">171057</a></dd>
<dt>Author</dt> <dd>mitz@apple.com</dd>
<dt>Date</dt> <dd>2014-07-13 12:39:45 -0700 (Sun, 13 Jul 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre><rdar://problem/17295636> [Cocoa] Include element snapshot in _WKActivatedElementInfo
https://bugs.webkit.org/show_bug.cgi?id=134872
Reviewed by Sam Weinig.
* Shared/InteractionInformationAtPosition.cpp:
(WebKit::InteractionInformationAtPosition::encode): Encode the image if there is one.
(WebKit::InteractionInformationAtPosition::decode): Decode the image if there is one.
* Shared/InteractionInformationAtPosition.h: Added an image member to the struct.
* UIProcess/API/Cocoa/_WKActivatedElementInfo.h: Exposed the boundingRect property and added
an image property.
* UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
(-[_WKActivatedElementInfo _initWithType:URL:location:title:rect:image:]): Added an image
parameter, which is stored in a new ivar.
(-[_WKActivatedElementInfo image]): Added this getter, which converts the ShareableBitmap
into a cached Cocoa image and returns it.
* UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h: Added image parameter to the
initializer, removed _boundingRect property declaration from here.
* UIProcess/ios/WKActionSheetAssistant.mm:
(-[WKActionSheetAssistant showImageSheet]): Pass the image from the position information
into the _WKActivatedElementInfo initializer.
(-[WKActionSheetAssistant showLinkSheet]): Ditto.
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::snapshotNode): Added.
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getPositionInformation): If the element is a link or an image, store a
snapshot of it in the image member of the InteractionInformationAtPosition.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebKit2ChangeLog">trunk/Source/WebKit2/ChangeLog</a></li>
<li><a href="#trunkSourceWebKit2SharedInteractionInformationAtPositioncpp">trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp</a></li>
<li><a href="#trunkSourceWebKit2SharedInteractionInformationAtPositionh">trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKActivatedElementInfoh">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKActivatedElementInfomm">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm</a></li>
<li><a href="#trunkSourceWebKit2UIProcessAPICocoa_WKActivatedElementInfoInternalh">trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h</a></li>
<li><a href="#trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm">trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm</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="#trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm">trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebKit2ChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/ChangeLog (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/ChangeLog        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/ChangeLog        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -1,5 +1,40 @@
</span><span class="cx"> 2014-07-13 Dan Bernstein <mitz@apple.com>
</span><span class="cx">
</span><ins>+ <rdar://problem/17295636> [Cocoa] Include element snapshot in _WKActivatedElementInfo
+ https://bugs.webkit.org/show_bug.cgi?id=134872
+
+ Reviewed by Sam Weinig.
+
+ * Shared/InteractionInformationAtPosition.cpp:
+ (WebKit::InteractionInformationAtPosition::encode): Encode the image if there is one.
+ (WebKit::InteractionInformationAtPosition::decode): Decode the image if there is one.
+ * Shared/InteractionInformationAtPosition.h: Added an image member to the struct.
+
+ * UIProcess/API/Cocoa/_WKActivatedElementInfo.h: Exposed the boundingRect property and added
+ an image property.
+ * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm:
+ (-[_WKActivatedElementInfo _initWithType:URL:location:title:rect:image:]): Added an image
+ parameter, which is stored in a new ivar.
+ (-[_WKActivatedElementInfo image]): Added this getter, which converts the ShareableBitmap
+ into a cached Cocoa image and returns it.
+ * UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h: Added image parameter to the
+ initializer, removed _boundingRect property declaration from here.
+
+ * UIProcess/ios/WKActionSheetAssistant.mm:
+ (-[WKActionSheetAssistant showImageSheet]): Pass the image from the position information
+ into the _WKActivatedElementInfo initializer.
+ (-[WKActionSheetAssistant showLinkSheet]): Ditto.
+
+ * WebProcess/WebPage/WebPage.cpp:
+ (WebKit::WebPage::snapshotNode): Added.
+ * WebProcess/WebPage/WebPage.h:
+
+ * WebProcess/WebPage/ios/WebPageIOS.mm:
+ (WebKit::WebPage::getPositionInformation): If the element is a link or an image, store a
+ snapshot of it in the image member of the InteractionInformationAtPosition.
+
+2014-07-13 Dan Bernstein <mitz@apple.com>
+
</ins><span class="cx"> [Cocoa] Clean up session state API a little
</span><span class="cx"> https://bugs.webkit.org/show_bug.cgi?id=134871
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedInteractionInformationAtPositioncpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -42,6 +42,11 @@
</span><span class="cx"> encoder << url;
</span><span class="cx"> encoder << title;
</span><span class="cx"> encoder << bounds;
</span><ins>+
+ ShareableBitmap::Handle handle;
+ if (image)
+ image->createHandle(handle, SharedMemory::ReadOnly);
+ encoder << handle;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> bool InteractionInformationAtPosition::decode(IPC::ArgumentDecoder& decoder, InteractionInformationAtPosition& result)
</span><span class="lines">@@ -70,6 +75,13 @@
</span><span class="cx"> if (!decoder.decode(result.bounds))
</span><span class="cx"> return false;
</span><span class="cx">
</span><ins>+ ShareableBitmap::Handle handle;
+ if (!decoder.decode(handle))
+ return false;
+
+ if (!handle.isNull())
+ result.image = ShareableBitmap::create(handle, SharedMemory::ReadOnly);
+
</ins><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx"> #endif
</span></span></pre></div>
<a id="trunkSourceWebKit2SharedInteractionInformationAtPositionh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #define InteractionInformationAtPosition_h
</span><span class="cx">
</span><span class="cx"> #include "ArgumentCoders.h"
</span><ins>+#include "ShareableBitmap.h"
</ins><span class="cx"> #include <WebCore/IntPoint.h>
</span><span class="cx"> #include <WebCore/SelectionRect.h>
</span><span class="cx"> #include <wtf/text/WTFString.h>
</span><span class="lines">@@ -50,6 +51,7 @@
</span><span class="cx"> String url;
</span><span class="cx"> String title;
</span><span class="cx"> WebCore::IntRect bounds;
</span><ins>+ RefPtr<ShareableBitmap> image;
</ins><span class="cx">
</span><span class="cx"> void encode(IPC::ArgumentEncoder&) const;
</span><span class="cx"> static bool decode(IPC::ArgumentDecoder&, InteractionInformationAtPosition&);
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKActivatedElementInfoh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -27,7 +27,11 @@
</span><span class="cx">
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx">
</span><del>-#import <Foundation/Foundation.h>
</del><ins>+#if TARGET_OS_IPHONE
+@class UIImage;
+#else
+@class NSImage;
+#endif
</ins><span class="cx">
</span><span class="cx"> typedef NS_ENUM(NSInteger, _WKActivatedElementType) {
</span><span class="cx"> _WKActivatedElementTypeLink,
</span><span class="lines">@@ -40,6 +44,12 @@
</span><span class="cx"> @property (nonatomic, readonly) NSURL *URL;
</span><span class="cx"> @property (nonatomic, readonly) NSString *title;
</span><span class="cx"> @property (nonatomic, readonly) _WKActivatedElementType type;
</span><ins>+@property (nonatomic, readonly) CGRect boundingRect;
+#if TARGET_OS_IPHONE
+@property (nonatomic, readonly, copy) UIImage *image;
+#else
+@property (nonatomic, readonly, copy) NSImage *image;
+#endif
</ins><span class="cx">
</span><span class="cx"> @end
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKActivatedElementInfomm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -28,16 +28,31 @@
</span><span class="cx">
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx">
</span><ins>+#import "ShareableBitmap.h"
</ins><span class="cx"> #import <wtf/RetainPtr.h>
</span><span class="cx">
</span><ins>+#if PLATFORM(IOS)
+#import <UIKit/UIImage.h>
+#endif
+
+#if PLATFORM(MAC)
+#import <AppKit/NSImage.h>
+#endif
+
</ins><span class="cx"> @implementation _WKActivatedElementInfo {
</span><span class="cx"> RetainPtr<NSURL> _URL;
</span><span class="cx"> RetainPtr<NSString> _title;
</span><span class="cx"> CGPoint _interactionLocation;
</span><del>- CGRect _boundingRect;
</del><ins>+ RefPtr<WebKit::ShareableBitmap> _image;
+#if PLATFORM(IOS)
+ RetainPtr<UIImage> _uiImage;
+#endif
+#if PLATFORM(MAC)
+ RetainPtr<NSImage> _nsImage;
+#endif
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-- (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect
</del><ins>+- (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image
</ins><span class="cx"> {
</span><span class="cx"> if (!(self = [super init]))
</span><span class="cx"> return nil;
</span><span class="lines">@@ -47,6 +62,7 @@
</span><span class="cx"> _title = adoptNS([title copy]);
</span><span class="cx"> _boundingRect = rect;
</span><span class="cx"> _type = type;
</span><ins>+ _image = image;
</ins><span class="cx">
</span><span class="cx"> return self;
</span><span class="cx"> }
</span><span class="lines">@@ -61,16 +77,43 @@
</span><span class="cx"> return _title.get();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-- (CGRect)_boundingRect
</del><ins>+- (CGPoint)_interactionLocation
</ins><span class="cx"> {
</span><del>- return _boundingRect;
</del><ins>+ return _interactionLocation;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-- (CGPoint)_interactionLocation
</del><ins>+#if PLATFORM(IOS)
+- (UIImage *)image
</ins><span class="cx"> {
</span><del>- return _interactionLocation;
</del><ins>+ if (_uiImage)
+ return [[_uiImage copy] autorelease];
+
+ if (!_image)
+ return nil;
+
+ _uiImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]);
+ _image = nullptr;
+
+ return [[_uiImage copy] autorelease];
</ins><span class="cx"> }
</span><ins>+#endif
</ins><span class="cx">
</span><ins>+#if PLATFORM(MAC)
+- (NSImage *)image
+{
+ if (_nsImage)
+ return [[_nsImage copy] autorelease];
+
+ if (!_image)
+ return nil;
+
+ _nsImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]);
+ _image = nullptr;
+
+ return [[_nsImage copy] autorelease];
+}
+#endif
+
</ins><span class="cx"> @end
</span><span class="cx">
</span><span class="cx"> #endif // WK_API_ENABLED
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessAPICocoa_WKActivatedElementInfoInternalh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -27,12 +27,15 @@
</span><span class="cx">
</span><span class="cx"> #if WK_API_ENABLED
</span><span class="cx">
</span><ins>+namespace WebKit {
+ class ShareableBitmap;
+}
+
</ins><span class="cx"> @interface _WKActivatedElementInfo ()
</span><span class="cx">
</span><del>-- (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect;
</del><ins>+- (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image;
</ins><span class="cx">
</span><span class="cx"> @property (nonatomic, readonly) CGPoint _interactionLocation;
</span><del>-@property (nonatomic, readonly) CGRect _boundingRect;
</del><span class="cx">
</span><span class="cx"> @end
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2UIProcessiosWKActionSheetAssistantmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -233,7 +233,7 @@
</span><span class="cx"> [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeCopy]];
</span><span class="cx">
</span><span class="cx"> auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage
</span><del>- URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds]);
</del><ins>+ URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]);
</ins><span class="cx">
</span><span class="cx"> RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions));
</span><span class="cx">
</span><span class="lines">@@ -269,7 +269,7 @@
</span><span class="cx"> [defaultActions addObject:[_WKElementAction elementActionWithType:_WKElementActionTypeCopy]];
</span><span class="cx">
</span><span class="cx"> RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink
</span><del>- URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds]);
</del><ins>+ URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]);
</ins><span class="cx">
</span><span class="cx"> RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions));
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPagecpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -1691,6 +1691,57 @@
</span><span class="cx"> return snapshot.release();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+PassRefPtr<WebImage> WebPage::snapshotNode(WebCore::Node& node, SnapshotOptions options, unsigned maximumPixelCount)
+{
+ Frame* coreFrame = m_mainFrame->coreFrame();
+ if (!coreFrame)
+ return nullptr;
+
+ FrameView* frameView = coreFrame->view();
+ if (!frameView)
+ return nullptr;
+
+ if (!node.renderer())
+ return nullptr;
+
+ LayoutRect topLevelRect;
+ IntRect snapshotRect = pixelSnappedIntRect(node.renderer()->paintingRootRect(topLevelRect));
+
+ double scaleFactor = 1;
+ IntSize snapshotSize = snapshotRect.size();
+ unsigned maximumHeight = maximumPixelCount / snapshotSize.width();
+ if (maximumHeight < static_cast<unsigned>(snapshotSize.height())) {
+ scaleFactor = static_cast<double>(maximumHeight) / snapshotSize.height();
+ snapshotSize = IntSize(snapshotSize.width() * scaleFactor, maximumHeight);
+ }
+
+ RefPtr<WebImage> snapshot = WebImage::create(snapshotSize, snapshotOptionsToImageOptions(options));
+ if (!snapshot->bitmap())
+ return nullptr;
+
+ auto graphicsContext = snapshot->bitmap()->createGraphicsContext();
+
+ if (!(options & SnapshotOptionsExcludeDeviceScaleFactor)) {
+ double deviceScaleFactor = corePage()->deviceScaleFactor();
+ graphicsContext->applyDeviceScaleFactor(deviceScaleFactor);
+ scaleFactor /= deviceScaleFactor;
+ }
+
+ graphicsContext->scale(FloatSize(scaleFactor, scaleFactor));
+ graphicsContext->translate(-snapshotRect.x(), -snapshotRect.y());
+
+ Color savedBackgroundColor = frameView->baseBackgroundColor();
+ frameView->setBaseBackgroundColor(Color::transparent);
+ frameView->setNodeToDraw(&node);
+
+ frameView->paintContentsForSnapshot(graphicsContext.get(), snapshotRect, FrameView::ExcludeSelection, FrameView::DocumentCoordinates);
+
+ frameView->setBaseBackgroundColor(savedBackgroundColor);
+ frameView->setNodeToDraw(nullptr);
+
+ return snapshot.release();
+}
+
</ins><span class="cx"> void WebPage::pageDidScroll()
</span><span class="cx"> {
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageWebPageh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -440,6 +440,7 @@
</span><span class="cx">
</span><span class="cx"> PassRefPtr<WebImage> scaledSnapshotWithOptions(const WebCore::IntRect&, double additionalScaleFactor, SnapshotOptions);
</span><span class="cx"> PassRefPtr<WebImage> snapshotAtSize(const WebCore::IntRect&, const WebCore::IntSize& bitmapSize, SnapshotOptions);
</span><ins>+ PassRefPtr<WebImage> snapshotNode(WebCore::Node&, SnapshotOptions, unsigned maximumPixelCount = std::numeric_limits<unsigned>::max());
</ins><span class="cx">
</span><span class="cx"> static const WebEvent* currentEvent();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebKit2WebProcessWebPageiosWebPageIOSmm"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm (171056 => 171057)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-07-13 18:55:43 UTC (rev 171056)
+++ trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm        2014-07-13 19:39:45 UTC (rev 171057)
</span><span class="lines">@@ -1849,6 +1849,11 @@
</span><span class="cx"> linkElement = element;
</span><span class="cx"> elementIsLinkOrImage = true;
</span><span class="cx"> }
</span><ins>+
+ if (elementIsLinkOrImage) {
+ // Ensure that the image contains at most 600K pixels, so that it is not too big.
+ info.image = snapshotNode(*element, SnapshotOptionsShareable, 600 * 1024)->bitmap();
+ }
</ins><span class="cx"> if (linkElement)
</span><span class="cx"> info.url = [(NSURL *)linkElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkElement->getAttribute(HTMLNames::hrefAttr))) absoluteString];
</span><span class="cx"> info.title = element->fastGetAttribute(HTMLNames::titleAttr).string();
</span></span></pre>
</div>
</div>
</body>
</html>