[WK2] Expose image via WKBundleHitTestResult API.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 21:01:26 +0000 (21:01 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 12 Dec 2017 21:01:26 +0000 (21:01 +0000)
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:

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ImageSource.h
Source/WebKit/ChangeLog
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp
Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h
Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp
Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h

index 4c1c173..faac1fe 100644 (file)
@@ -1,3 +1,14 @@
+2017-12-12  Zach Li  <zachli@apple.com>
+        [WK2] Expose image via WKBundleHitTestResult API.
+        https://bugs.webkit.org/show_bug.cgi?id=180552.
+        rdar://problem/23951521
+
+        Reviewed by Simon Fraser.
+
+        * platform/graphics/ImageSource.h:
+        This method will be used by clients outside WebCore, so
+        add WEBCORE_EXPORT.
+
 2017-12-12  Simon Fraser  <simon.fraser@apple.com>
 
         Remove ColorSpaceDeviceRGB and most users of the obsolete deviceRGB colorspace
index f10e4c1..0e5139d 100644 (file)
@@ -95,7 +95,7 @@ public:
     std::optional<IntPoint> hotSpot();
 
     // Image metadata which is calculated from the first ImageFrame.
-    IntSize size();
+    WEBCORE_EXPORT IntSize size();
     IntSize sizeRespectingOrientation();
     Color singlePixelSolidColor();
     SubsamplingLevel maximumSubsamplingLevel();
index a381689..c7395ce 100644 (file)
@@ -1,3 +1,22 @@
+2017-12-12  Zach Li  <zachli@apple.com>
+
+        [WK2] Expose image via WKBundleHitTestResult API.
+        https://bugs.webkit.org/show_bug.cgi?id=180552.
+        rdar://problem/23951521
+
+        Reviewed by Simon Fraser.
+
+        * 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:
+
 2017-12-12  Simon Fraser  <simon.fraser@apple.com>
 
         Remove ColorSpaceDeviceRGB and most users of the obsolete deviceRGB colorspace
index 2f6d2d0..693343c 100644 (file)
@@ -31,6 +31,7 @@
 #include "WKAPICast.h"
 #include "WKBundleAPICast.h"
 #include "WebFrame.h"
+#include "WebImage.h"
 
 using namespace WebKit;
 
@@ -106,6 +107,12 @@ WKRect WKBundleHitTestResultGetImageRect(WKBundleHitTestResultRef hitTestResultR
     return toAPI(toImpl(hitTestResultRef)->imageRect());
 }
 
+WKImageRef WKBundleHitTestResultCopyImage(WKBundleHitTestResultRef hitTestResultRef)
+{
+    RefPtr<WebImage> webImage = toImpl(hitTestResultRef)->image();
+    return toAPI(webImage.leakRef());
+}
+
 bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResultRef)
 {
     return toImpl(hitTestResultRef)->isSelected();
index 66388bf..51418da 100644 (file)
@@ -58,6 +58,7 @@ WK_EXPORT bool WKBundleHitTestResultIsDownloadableMedia(WKBundleHitTestResultRef
 WK_EXPORT WKBundleHitTestResultMediaType WKBundleHitTestResultGetMediaType(WKBundleHitTestResultRef hitTestResult);
 
 WK_EXPORT WKRect WKBundleHitTestResultGetImageRect(WKBundleHitTestResultRef hitTestResult);
+WK_EXPORT WKImageRef WKBundleHitTestResultCopyImage(WKBundleHitTestResultRef hitTestResult);
 WK_EXPORT bool WKBundleHitTestResultGetIsSelected(WKBundleHitTestResultRef hitTestResult);
 
 WK_EXPORT WKStringRef WKBundleHitTestResultCopyLinkLabel(WKBundleHitTestResultRef hitTestResult);
index 72ae772..381063e 100644 (file)
 #include "InjectedBundleNodeHandle.h"
 #include "WebFrame.h"
 #include "WebFrameLoaderClient.h"
+#include "WebImage.h"
+#include <WebCore/BitmapImage.h>
 #include <WebCore/Document.h>
 #include <WebCore/Element.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameLoader.h>
 #include <WebCore/FrameView.h>
+#include <WebCore/GraphicsContext.h>
 #include <WebCore/URL.h>
 #include <wtf/text/WTFString.h>
 
@@ -167,6 +170,24 @@ IntRect InjectedBundleHitTestResult::imageRect() const
     return view->contentsToRootView(imageRect);
 }
 
+RefPtr<WebImage> InjectedBundleHitTestResult::image() const
+{
+    Image* image = m_hitTestResult.image();
+    // For now, we only handle bitmap images.
+    if (!is<BitmapImage>(image))
+        return nullptr;
+
+    BitmapImage& bitmapImage = downcast<BitmapImage>(*image);
+    IntSize size(bitmapImage.size());
+    auto webImage = WebImage::create(size, static_cast<ImageOptions>(0));
+
+    // FIXME: need to handle EXIF rotation.
+    auto graphicsContext = webImage->bitmap().createGraphicsContext();
+    graphicsContext->drawImage(bitmapImage, {{ }, size});
+
+    return webImage;
+}
+
 bool InjectedBundleHitTestResult::isSelected() const
 {
     return m_hitTestResult.isSelected();
index 14e3e67..a16f0c6 100644 (file)
@@ -37,6 +37,7 @@ namespace WebKit {
 
 class InjectedBundleNodeHandle;
 class WebFrame;
+class WebImage;
 
 class InjectedBundleHitTestResult : public API::ObjectImpl<API::Object::Type::BundleHitTestResult> {
 public:
@@ -63,6 +64,7 @@ public:
     String linkSuggestedFilename() const;
     
     WebCore::IntRect imageRect() const;
+    RefPtr<WebImage> image() const;
     
     bool isSelected() const;