Changeset 171057 in webkit


Ignore:
Timestamp:
Jul 13, 2014 12:39:45 PM (10 years ago)
Author:
mitz@apple.com
Message:

<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.

Location:
trunk/Source/WebKit2
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r171050 r171057  
     12014-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
    1362014-07-13  Dan Bernstein  <mitz@apple.com>
    237
  • trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.cpp

    r167096 r171057  
    4343    encoder << title;
    4444    encoder << bounds;
     45
     46    ShareableBitmap::Handle handle;
     47    if (image)
     48        image->createHandle(handle, SharedMemory::ReadOnly);
     49    encoder << handle;
    4550}
    4651
     
    7176        return false;
    7277
     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
    7385    return true;
    7486}
  • trunk/Source/WebKit2/Shared/InteractionInformationAtPosition.h

    r167096 r171057  
    2828
    2929#include "ArgumentCoders.h"
     30#include "ShareableBitmap.h"
    3031#include <WebCore/IntPoint.h>
    3132#include <WebCore/SelectionRect.h>
     
    5152    String title;
    5253    WebCore::IntRect bounds;
     54    RefPtr<ShareableBitmap> image;
    5355
    5456    void encode(IPC::ArgumentEncoder&) const;
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.h

    r168566 r171057  
    2828#if WK_API_ENABLED
    2929
    30 #import <Foundation/Foundation.h>
     30#if TARGET_OS_IPHONE
     31@class UIImage;
     32#else
     33@class NSImage;
     34#endif
    3135
    3236typedef NS_ENUM(NSInteger, _WKActivatedElementType) {
     
    4145@property (nonatomic, readonly) NSString *title;
    4246@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
    4353
    4454@end
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfo.mm

    r164666 r171057  
    2929#if WK_API_ENABLED
    3030
     31#import "ShareableBitmap.h"
    3132#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
    3241
    3342@implementation _WKActivatedElementInfo  {
     
    3544    RetainPtr<NSString> _title;
    3645    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
    3853}
    3954
    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
    4156{
    4257    if (!(self = [super init]))
     
    4863    _boundingRect = rect;
    4964    _type = type;
     65    _image = image;
    5066
    5167    return self;
     
    6278}
    6379
    64 - (CGRect)_boundingRect
    65 {
    66     return _boundingRect;
    67 }
    68 
    6980- (CGPoint)_interactionLocation
    7081{
     
    7283}
    7384
     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
    74117@end
    75118
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/_WKActivatedElementInfoInternal.h

    r164666 r171057  
    2828#if WK_API_ENABLED
    2929
     30namespace WebKit {
     31    class ShareableBitmap;
     32}
     33
    3034@interface _WKActivatedElementInfo ()
    3135
    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;
    3337
    3438@property (nonatomic, readonly) CGPoint _interactionLocation;
    35 @property (nonatomic, readonly) CGRect _boundingRect;
    3639
    3740@end
  • trunk/Source/WebKit2/UIProcess/ios/WKActionSheetAssistant.mm

    r170774 r171057  
    234234
    235235    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()]);
    237237
    238238    RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions));
     
    270270
    271271    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()]);
    273273
    274274    RetainPtr<NSArray> actions = _view.page->uiClient().actionsForElement(elementInfo.get(), WTF::move(defaultActions));
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp

    r171015 r171057  
    16921692}
    16931693
     1694PassRefPtr<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
    16941745void WebPage::pageDidScroll()
    16951746{
  • trunk/Source/WebKit2/WebProcess/WebPage/WebPage.h

    r170981 r171057  
    441441    PassRefPtr<WebImage> scaledSnapshotWithOptions(const WebCore::IntRect&, double additionalScaleFactor, SnapshotOptions);
    442442    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());
    443444
    444445    static const WebEvent* currentEvent();
  • trunk/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm

    r170981 r171057  
    18501850                elementIsLinkOrImage = true;
    18511851            }
     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            }
    18521857            if (linkElement)
    18531858                info.url = [(NSURL *)linkElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkElement->getAttribute(HTMLNames::hrefAttr))) absoluteString];
Note: See TracChangeset for help on using the changeset viewer.