Changeset 225798 in webkit


Ignore:
Timestamp:
Dec 12, 2017 1:01:26 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

[WK2] Expose image via WKBundleHitTestResult API.
https://bugs.webkit.org/show_bug.cgi?id=180552.
rdar://problem/23951521

Patch by Zach Li <zachli@apple.com> on 2017-12-12
Reviewed by Simon Fraser.

Source/WebCore:

  • platform/graphics/ImageSource.h:

This method will be used by clients outside WebCore, so
add WEBCORE_EXPORT.

Source/WebKit:

  • WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:

(WKBundleHitTestResultGetImage):

  • WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:
  • WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:

(WebKit::InjectedBundleHitTestResult::image const):
Convert from WebCore::Image to WebImage by creating a WebImage
and paint the WebCore::Image into its graphics context. For now,
only handle bitmap images.

  • WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:
Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r225797 r225798  
     12017-12-12  Zach Li  <zachli@apple.com>
     2        [WK2] Expose image via WKBundleHitTestResult API.
     3        https://bugs.webkit.org/show_bug.cgi?id=180552.
     4        rdar://problem/23951521
     5
     6        Reviewed by Simon Fraser.
     7
     8        * platform/graphics/ImageSource.h:
     9        This method will be used by clients outside WebCore, so
     10        add WEBCORE_EXPORT.
     11
    1122017-12-12  Simon Fraser  <simon.fraser@apple.com>
    213
  • trunk/Source/WebCore/platform/graphics/ImageSource.h

    r225428 r225798  
    9696
    9797    // Image metadata which is calculated from the first ImageFrame.
    98     IntSize size();
     98    WEBCORE_EXPORT IntSize size();
    9999    IntSize sizeRespectingOrientation();
    100100    Color singlePixelSolidColor();
  • trunk/Source/WebKit/ChangeLog

    r225797 r225798  
     12017-12-12  Zach Li  <zachli@apple.com>
     2
     3        [WK2] Expose image via WKBundleHitTestResult API.
     4        https://bugs.webkit.org/show_bug.cgi?id=180552.
     5        rdar://problem/23951521
     6
     7        Reviewed by Simon Fraser.
     8
     9        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:
     10        (WKBundleHitTestResultGetImage):
     11        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:
     12
     13        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
     14        (WebKit::InjectedBundleHitTestResult::image const):
     15        Convert from WebCore::Image to WebImage by creating a WebImage
     16        and paint the WebCore::Image into its graphics context. For now,
     17        only handle bitmap images.
     18        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:
     19
    1202017-12-12  Simon Fraser  <simon.fraser@apple.com>
    221
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp

    r207579 r225798  
    3232#include "WKBundleAPICast.h"
    3333#include "WebFrame.h"
     34#include "WebImage.h"
    3435
    3536using namespace WebKit;
     
    107108}
    108109
     110WKImageRef WKBundleHitTestResultCopyImage(WKBundleHitTestResultRef hitTestResultRef)
     111{
     112    RefPtr<WebImage> webImage = toImpl(hitTestResultRef)->image();
     113    return toAPI(webImage.leakRef());
     114}
     115
    109116bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResultRef)
    110117{
  • trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h

    r207579 r225798  
    5959
    6060WK_EXPORT WKRect WKBundleHitTestResultGetImageRect(WKBundleHitTestResultRef hitTestResult);
     61WK_EXPORT WKImageRef WKBundleHitTestResultCopyImage(WKBundleHitTestResultRef hitTestResult);
    6162WK_EXPORT bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResult);
    6263
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp

    r216810 r225798  
    3030#include "WebFrame.h"
    3131#include "WebFrameLoaderClient.h"
     32#include "WebImage.h"
     33#include <WebCore/BitmapImage.h>
    3234#include <WebCore/Document.h>
    3335#include <WebCore/Element.h>
     
    3537#include <WebCore/FrameLoader.h>
    3638#include <WebCore/FrameView.h>
     39#include <WebCore/GraphicsContext.h>
    3740#include <WebCore/URL.h>
    3841#include <wtf/text/WTFString.h>
     
    168171}
    169172
     173RefPtr<WebImage> InjectedBundleHitTestResult::image() const
     174{
     175    Image* image = m_hitTestResult.image();
     176    // For now, we only handle bitmap images.
     177    if (!is<BitmapImage>(image))
     178        return nullptr;
     179
     180    BitmapImage& bitmapImage = downcast<BitmapImage>(*image);
     181    IntSize size(bitmapImage.size());
     182    auto webImage = WebImage::create(size, static_cast<ImageOptions>(0));
     183
     184    // FIXME: need to handle EXIF rotation.
     185    auto graphicsContext = webImage->bitmap().createGraphicsContext();
     186    graphicsContext->drawImage(bitmapImage, {{ }, size});
     187
     188    return webImage;
     189}
     190
    170191bool InjectedBundleHitTestResult::isSelected() const
    171192{
  • trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h

    r216810 r225798  
    3838class InjectedBundleNodeHandle;
    3939class WebFrame;
     40class WebImage;
    4041
    4142class InjectedBundleHitTestResult : public API::ObjectImpl<API::Object::Type::BundleHitTestResult> {
     
    6465   
    6566    WebCore::IntRect imageRect() const;
     67    RefPtr<WebImage> image() const;
    6668   
    6769    bool isSelected() const;
Note: See TracChangeset for help on using the changeset viewer.