Changeset 171057 in webkit
- Timestamp:
- Jul 13, 2014 12:39:45 PM (10 years ago)
- Location:
- trunk/Source/WebKit2
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit2/ChangeLog
r171050 r171057 1 2014-07-13 Dan Bernstein <mitz@apple.com> 2 3 <rdar://problem/17295636> [Cocoa] Include element snapshot in _WKActivatedElementInfo 4 https://bugs.webkit.org/show_bug.cgi?id=134872 5 6 Reviewed by Sam Weinig. 7 8 * Shared/InteractionInformationAtPosition.cpp: 9 (WebKit::InteractionInformationAtPosition::encode): Encode the image if there is one. 10 (WebKit::InteractionInformationAtPosition::decode): Decode the image if there is one. 11 * Shared/InteractionInformationAtPosition.h: Added an image member to the struct. 12 13 * UIProcess/API/Cocoa/_WKActivatedElementInfo.h: Exposed the boundingRect property and added 14 an image property. 15 * UIProcess/API/Cocoa/_WKActivatedElementInfo.mm: 16 (-[_WKActivatedElementInfo _initWithType:URL:location:title:rect:image:]): Added an image 17 parameter, which is stored in a new ivar. 18 (-[_WKActivatedElementInfo image]): Added this getter, which converts the ShareableBitmap 19 into a cached Cocoa image and returns it. 20 * UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h: Added image parameter to the 21 initializer, removed _boundingRect property declaration from here. 22 23 * UIProcess/ios/WKActionSheetAssistant.mm: 24 (-[WKActionSheetAssistant showImageSheet]): Pass the image from the position information 25 into the _WKActivatedElementInfo initializer. 26 (-[WKActionSheetAssistant showLinkSheet]): Ditto. 27 28 * WebProcess/WebPage/WebPage.cpp: 29 (WebKit::WebPage::snapshotNode): Added. 30 * WebProcess/WebPage/WebPage.h: 31 32 * WebProcess/WebPage/ios/WebPageIOS.mm: 33 (WebKit::WebPage::getPositionInformation): If the element is a link or an image, store a 34 snapshot of it in the image member of the InteractionInformationAtPosition. 35 1 36 2014-07-13 Dan Bernstein <mitz@apple.com> 2 37 -
trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp
r167096 r171057 43 43 encoder << title; 44 44 encoder << bounds; 45 46 ShareableBitmap::Handle handle; 47 if (image) 48 image->createHandle(handle, SharedMemory::ReadOnly); 49 encoder << handle; 45 50 } 46 51 … … 71 76 return false; 72 77 78 ShareableBitmap::Handle handle; 79 if (!decoder.decode(handle)) 80 return false; 81 82 if (!handle.isNull()) 83 result.image = ShareableBitmap::create(handle, SharedMemory::ReadOnly); 84 73 85 return true; 74 86 } -
trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h
r167096 r171057 28 28 29 29 #include "ArgumentCoders.h" 30 #include "ShareableBitmap.h" 30 31 #include <WebCore/IntPoint.h> 31 32 #include <WebCore/SelectionRect.h> … … 51 52 String title; 52 53 WebCore::IntRect bounds; 54 RefPtr<ShareableBitmap> image; 53 55 54 56 void encode(IPC::ArgumentEncoder&) const; -
trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h
r168566 r171057 28 28 #if WK_API_ENABLED 29 29 30 #import <Foundation/Foundation.h> 30 #if TARGET_OS_IPHONE 31 @class UIImage; 32 #else 33 @class NSImage; 34 #endif 31 35 32 36 typedef NS_ENUM(NSInteger, _WKActivatedElementType) { … … 41 45 @property (nonatomic, readonly) NSString *title; 42 46 @property (nonatomic, readonly) _WKActivatedElementType type; 47 @property (nonatomic, readonly) CGRect boundingRect; 48 #if TARGET_OS_IPHONE 49 @property (nonatomic, readonly, copy) UIImage *image; 50 #else 51 @property (nonatomic, readonly, copy) NSImage *image; 52 #endif 43 53 44 54 @end -
trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm
r164666 r171057 29 29 #if WK_API_ENABLED 30 30 31 #import "ShareableBitmap.h" 31 32 #import <wtf/RetainPtr.h> 33 34 #if PLATFORM(IOS) 35 #import <UIKit/UIImage.h> 36 #endif 37 38 #if PLATFORM(MAC) 39 #import <AppKit/NSImage.h> 40 #endif 32 41 33 42 @implementation _WKActivatedElementInfo { … … 35 44 RetainPtr<NSString> _title; 36 45 CGPoint _interactionLocation; 37 CGRect _boundingRect; 46 RefPtr<WebKit::ShareableBitmap> _image; 47 #if PLATFORM(IOS) 48 RetainPtr<UIImage> _uiImage; 49 #endif 50 #if PLATFORM(MAC) 51 RetainPtr<NSImage> _nsImage; 52 #endif 38 53 } 39 54 40 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect 55 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image 41 56 { 42 57 if (!(self = [super init])) … … 48 63 _boundingRect = rect; 49 64 _type = type; 65 _image = image; 50 66 51 67 return self; … … 62 78 } 63 79 64 - (CGRect)_boundingRect65 {66 return _boundingRect;67 }68 69 80 - (CGPoint)_interactionLocation 70 81 { … … 72 83 } 73 84 85 #if PLATFORM(IOS) 86 - (UIImage *)image 87 { 88 if (_uiImage) 89 return [[_uiImage copy] autorelease]; 90 91 if (!_image) 92 return nil; 93 94 _uiImage = adoptNS([[UIImage alloc] initWithCGImage:_image->makeCGImageCopy().get()]); 95 _image = nullptr; 96 97 return [[_uiImage copy] autorelease]; 98 } 99 #endif 100 101 #if PLATFORM(MAC) 102 - (NSImage *)image 103 { 104 if (_nsImage) 105 return [[_nsImage copy] autorelease]; 106 107 if (!_image) 108 return nil; 109 110 _nsImage = adoptNS([[NSImage alloc] initWithCGImage:_image->makeCGImageCopy().get() size:NSSizeFromCGSize(_boundingRect.size)]); 111 _image = nullptr; 112 113 return [[_nsImage copy] autorelease]; 114 } 115 #endif 116 74 117 @end 75 118 -
trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h
r164666 r171057 28 28 #if WK_API_ENABLED 29 29 30 namespace WebKit { 31 class ShareableBitmap; 32 } 33 30 34 @interface _WKActivatedElementInfo () 31 35 32 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect ;36 - (instancetype)_initWithType:(_WKActivatedElementType)type URL:(NSURL *)url location:(CGPoint)location title:(NSString *)title rect:(CGRect)rect image:(WebKit::ShareableBitmap*)image; 33 37 34 38 @property (nonatomic, readonly) CGPoint _interactionLocation; 35 @property (nonatomic, readonly) CGRect _boundingRect;36 39 37 40 @end -
trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm
r170774 r171057 234 234 235 235 auto elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeImage 236 URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds ]);236 URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]); 237 237 238 238 RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions)); … … 270 270 271 271 RetainPtr<_WKActivatedElementInfo> elementInfo = adoptNS([[_WKActivatedElementInfo alloc] _initWithType:_WKActivatedElementTypeLink 272 URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds ]);272 URL:targetURL location:positionInformation.point title:positionInformation.title rect:positionInformation.bounds image:positionInformation.image.get()]); 273 273 274 274 RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions)); -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp
r171015 r171057 1692 1692 } 1693 1693 1694 PassRefPtr<WebImage> WebPage::snapshotNode(WebCore::Node& node, SnapshotOptions options, unsigned maximumPixelCount) 1695 { 1696 Frame* coreFrame = m_mainFrame->coreFrame(); 1697 if (!coreFrame) 1698 return nullptr; 1699 1700 FrameView* frameView = coreFrame->view(); 1701 if (!frameView) 1702 return nullptr; 1703 1704 if (!node.renderer()) 1705 return nullptr; 1706 1707 LayoutRect topLevelRect; 1708 IntRect snapshotRect = pixelSnappedIntRect(node.renderer()->paintingRootRect(topLevelRect)); 1709 1710 double scaleFactor = 1; 1711 IntSize snapshotSize = snapshotRect.size(); 1712 unsigned maximumHeight = maximumPixelCount / snapshotSize.width(); 1713 if (maximumHeight < static_cast<unsigned>(snapshotSize.height())) { 1714 scaleFactor = static_cast<double>(maximumHeight) / snapshotSize.height(); 1715 snapshotSize = IntSize(snapshotSize.width() * scaleFactor, maximumHeight); 1716 } 1717 1718 RefPtr<WebImage> snapshot = WebImage::create(snapshotSize, snapshotOptionsToImageOptions(options)); 1719 if (!snapshot->bitmap()) 1720 return nullptr; 1721 1722 auto graphicsContext = snapshot->bitmap()->createGraphicsContext(); 1723 1724 if (!(options & SnapshotOptionsExcludeDeviceScaleFactor)) { 1725 double deviceScaleFactor = corePage()->deviceScaleFactor(); 1726 graphicsContext->applyDeviceScaleFactor(deviceScaleFactor); 1727 scaleFactor /= deviceScaleFactor; 1728 } 1729 1730 graphicsContext->scale(FloatSize(scaleFactor, scaleFactor)); 1731 graphicsContext->translate(-snapshotRect.x(), -snapshotRect.y()); 1732 1733 Color savedBackgroundColor = frameView->baseBackgroundColor(); 1734 frameView->setBaseBackgroundColor(Color::transparent); 1735 frameView->setNodeToDraw(&node); 1736 1737 frameView->paintContentsForSnapshot(graphicsContext.get(), snapshotRect, FrameView::ExcludeSelection, FrameView::DocumentCoordinates); 1738 1739 frameView->setBaseBackgroundColor(savedBackgroundColor); 1740 frameView->setNodeToDraw(nullptr); 1741 1742 return snapshot.release(); 1743 } 1744 1694 1745 void WebPage::pageDidScroll() 1695 1746 { -
trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h
r170981 r171057 441 441 PassRefPtr<WebImage> scaledSnapshotWithOptions(const WebCore::IntRect&, double additionalScaleFactor, SnapshotOptions); 442 442 PassRefPtr<WebImage> snapshotAtSize(const WebCore::IntRect&, const WebCore::IntSize& bitmapSize, SnapshotOptions); 443 PassRefPtr<WebImage> snapshotNode(WebCore::Node&, SnapshotOptions, unsigned maximumPixelCount = std::numeric_limits<unsigned>::max()); 443 444 444 445 static const WebEvent* currentEvent(); -
trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
r170981 r171057 1850 1850 elementIsLinkOrImage = true; 1851 1851 } 1852 1853 if (elementIsLinkOrImage) { 1854 // Ensure that the image contains at most 600K pixels, so that it is not too big. 1855 info.image = snapshotNode(*element, SnapshotOptionsShareable, 600 * 1024)->bitmap(); 1856 } 1852 1857 if (linkElement) 1853 1858 info.url = [(NSURL *)linkElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkElement->getAttribute(HTMLNames::hrefAttr))) absoluteString];
Note: See TracChangeset
for help on using the changeset viewer.