Title: [225798] trunk/Source
- Revision
- 225798
- Author
- commit-qu...@webkit.org
- Date
- 2017-12-12 13:01:26 -0800 (Tue, 12 Dec 2017)
Log Message
[WK2] Expose image via WKBundleHitTestResult API.
https://bugs.webkit.org/show_bug.cgi?id=180552.
rdar://problem/23951521
Patch by Zach Li <zac...@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:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (225797 => 225798)
--- trunk/Source/WebCore/ChangeLog 2017-12-12 21:00:37 UTC (rev 225797)
+++ trunk/Source/WebCore/ChangeLog 2017-12-12 21:01:26 UTC (rev 225798)
@@ -1,3 +1,14 @@
+2017-12-12 Zach Li <zac...@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.fra...@apple.com>
Remove ColorSpaceDeviceRGB and most users of the obsolete deviceRGB colorspace
Modified: trunk/Source/WebCore/platform/graphics/ImageSource.h (225797 => 225798)
--- trunk/Source/WebCore/platform/graphics/ImageSource.h 2017-12-12 21:00:37 UTC (rev 225797)
+++ trunk/Source/WebCore/platform/graphics/ImageSource.h 2017-12-12 21:01:26 UTC (rev 225798)
@@ -95,7 +95,7 @@
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();
Modified: trunk/Source/WebKit/ChangeLog (225797 => 225798)
--- trunk/Source/WebKit/ChangeLog 2017-12-12 21:00:37 UTC (rev 225797)
+++ trunk/Source/WebKit/ChangeLog 2017-12-12 21:01:26 UTC (rev 225798)
@@ -1,3 +1,22 @@
+2017-12-12 Zach Li <zac...@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.fra...@apple.com>
Remove ColorSpaceDeviceRGB and most users of the obsolete deviceRGB colorspace
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp (225797 => 225798)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp 2017-12-12 21:00:37 UTC (rev 225797)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp 2017-12-12 21:01:26 UTC (rev 225798)
@@ -31,6 +31,7 @@
#include "WKAPICast.h"
#include "WKBundleAPICast.h"
#include "WebFrame.h"
+#include "WebImage.h"
using namespace WebKit;
@@ -106,6 +107,12 @@
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();
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h (225797 => 225798)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h 2017-12-12 21:00:37 UTC (rev 225797)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h 2017-12-12 21:01:26 UTC (rev 225798)
@@ -58,6 +58,7 @@
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);
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp (225797 => 225798)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp 2017-12-12 21:00:37 UTC (rev 225797)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp 2017-12-12 21:01:26 UTC (rev 225798)
@@ -29,11 +29,14 @@
#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 @@
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();
Modified: trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h (225797 => 225798)
--- trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h 2017-12-12 21:00:37 UTC (rev 225797)
+++ trunk/Source/WebKit/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h 2017-12-12 21:01:26 UTC (rev 225798)
@@ -37,6 +37,7 @@
class InjectedBundleNodeHandle;
class WebFrame;
+class WebImage;
class InjectedBundleHitTestResult : public API::ObjectImpl<API::Object::Type::BundleHitTestResult> {
public:
@@ -63,6 +64,7 @@
String linkSuggestedFilename() const;
WebCore::IntRect imageRect() const;
+ RefPtr<WebImage> image() const;
bool isSelected() const;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes