Expose injected bundle SPI to get a node's URL element, get the visible selection...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Aug 2014 23:33:33 +0000 (23:33 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 19 Aug 2014 23:33:33 +0000 (23:33 +0000)
element, and snapshot that range
https://bugs.webkit.org/show_bug.cgi?id=136076

Patch by Peyton Randolph <prandolph@apple.com> on 2014-08-19
Reviewed by Tim Horton.

* WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:
(WKBundleHitTestResultCopyURLElementHandle): Added.
* WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:
* WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
(WKBundleNodeHandleCopyVisibleRange): Added.
* WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h:
* WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp:
(WKBundleRangeHandleGetBoundingRectInWindowCoordinates): Added.
(WKBundleRangeHandleCopySnapshotWithOptions): Added.
* WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h:
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
(WebKit::InjectedBundleNodeHandle::visibleRange): Added.
* WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h:
* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
(WebKit::InjectedBundleRangeHandle::boundingRectInWindowCoordinates): Added.
(WebKit::InjectedBundleRangeHandle::renderedImage): Added.
* WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h:
* WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
(WebKit::InjectedBundleHitTestResult::urlElementHandle): Added.
* WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:

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

14 files changed:
Source/WebCore/WebCore.exp.in
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h
Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp
Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h
Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp
Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp
Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h

index 03b20be..d0c69b5 100644 (file)
@@ -1321,6 +1321,7 @@ __ZN7WebCore8FormDataD1Ev
 __ZN7WebCore8Gradient12addColorStopEfRKNS_5ColorE
 __ZN7WebCore8GradientC1ERKNS_10FloatPointES3_
 __ZN7WebCore8GradientD1Ev
+__ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEENS0_10AnchorTypeE
 __ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEEiNS0_10AnchorTypeE
 __ZN7WebCore8Settings13gQTKitEnabledE
 __ZN7WebCore8Settings14setJavaEnabledEb
index 5ae31eb..b2e6540 100644 (file)
@@ -1,3 +1,32 @@
+2014-08-19  Peyton Randolph  <prandolph@apple.com>
+
+        Expose injected bundle SPI to get a node's URL element, get the visible selection range of that
+        element, and snapshot that range
+        https://bugs.webkit.org/show_bug.cgi?id=136076
+
+        Reviewed by Tim Horton.
+
+        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:
+        (WKBundleHitTestResultCopyURLElementHandle): Added.
+        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:
+        * WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
+        (WKBundleNodeHandleCopyVisibleRange): Added.
+        * WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h:
+        * WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp:
+        (WKBundleRangeHandleGetBoundingRectInWindowCoordinates): Added.
+        (WKBundleRangeHandleCopySnapshotWithOptions): Added.
+        * WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h:
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
+        (WebKit::InjectedBundleNodeHandle::visibleRange): Added.
+        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h:
+        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
+        (WebKit::InjectedBundleRangeHandle::boundingRectInWindowCoordinates): Added.
+        (WebKit::InjectedBundleRangeHandle::renderedImage): Added.
+        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h:
+        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
+        (WebKit::InjectedBundleHitTestResult::urlElementHandle): Added.
+        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:
+
 2014-08-19  Zalan Bujtas  <zalan@apple.com>
 
         Remove ENABLE(SUBPIXEL_LAYOUT).
index 60a4c68..5b9a011 100644 (file)
@@ -44,6 +44,12 @@ WKBundleNodeHandleRef WKBundleHitTestResultCopyNodeHandle(WKBundleHitTestResultR
     return toAPI(nodeHandle.release().leakRef());
 }
 
+WKBundleNodeHandleRef WKBundleHitTestResultCopyURLElementHandle(WKBundleHitTestResultRef hitTestResultRef)
+{
+    RefPtr<InjectedBundleNodeHandle> urlElementNodeHandle = toImpl(hitTestResultRef)->urlElementHandle();
+    return toAPI(urlElementNodeHandle.release().leakRef());
+}
+
 WKBundleFrameRef WKBundleHitTestResultGetFrame(WKBundleHitTestResultRef hitTestResultRef)
 {
     return toAPI(toImpl(hitTestResultRef)->frame());
index 12e72ec..40d3ccf 100644 (file)
@@ -43,6 +43,7 @@ typedef uint32_t WKBundleHitTestResultMediaType;
 WK_EXPORT WKTypeID WKBundleHitTestResultGetTypeID();
 
 WK_EXPORT WKBundleNodeHandleRef WKBundleHitTestResultCopyNodeHandle(WKBundleHitTestResultRef hitTestResult);
+WK_EXPORT WKBundleNodeHandleRef WKBundleHitTestResultCopyURLElementHandle(WKBundleHitTestResultRef hitTestResult);
 
 WK_EXPORT WKBundleFrameRef WKBundleHitTestResultGetFrame(WKBundleHitTestResultRef hitTestResult);
 WK_EXPORT WKBundleFrameRef WKBundleHitTestResultGetTargetFrame(WKBundleHitTestResultRef hitTestResult);
index cb3f9b6..0def2ae 100644 (file)
@@ -28,6 +28,7 @@
 #include "WKBundleNodeHandlePrivate.h"
 
 #include "InjectedBundleNodeHandle.h"
+#include "InjectedBundleRangeHandle.h"
 #include "WKAPICast.h"
 #include "WKBundleAPICast.h"
 #include "WebFrame.h"
@@ -63,6 +64,12 @@ WKImageRef WKBundleNodeHandleCopySnapshotWithOptions(WKBundleNodeHandleRef nodeH
     return toAPI(image.release().leakRef());
 }
 
+WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef nodeHandleRef)
+{
+    RefPtr<InjectedBundleRangeHandle> rangeHandle = toImpl(nodeHandleRef)->visibleRange();
+    return toAPI(rangeHandle.release().leakRef());
+}
+
 WKRect WKBundleNodeHandleGetElementBounds(WKBundleNodeHandleRef elementHandleRef)
 {
     return toAPI(toImpl(elementHandleRef)->elementBounds());
index c83bc31..02eca10 100644 (file)
@@ -45,6 +45,7 @@ WK_EXPORT WKBundleNodeHandleRef WKBundleNodeHandleCopyDocument(WKBundleNodeHandl
 
 WK_EXPORT WKRect WKBundleNodeHandleGetRenderRect(WKBundleNodeHandleRef nodeHandle, bool* isReplaced);
 WK_EXPORT WKImageRef WKBundleNodeHandleCopySnapshotWithOptions(WKBundleNodeHandleRef nodeHandle, WKSnapshotOptions options);
+WK_EXPORT WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef nodeHandle);
 
 /* Element Specific Operations */
 WK_EXPORT WKRect WKBundleNodeHandleGetElementBounds(WKBundleNodeHandleRef elementHandle);
index fb2f7d0..73b88c1 100644 (file)
@@ -30,6 +30,8 @@
 #include "InjectedBundleRangeHandle.h"
 #include "WKAPICast.h"
 #include "WKBundleAPICast.h"
+#include "WebImage.h"
+#include <WebCore/IntRect.h>
 
 using namespace WebKit;
 
@@ -43,3 +45,15 @@ WKBundleRangeHandleRef WKBundleRangeHandleCreate(JSContextRef contextRef, JSObje
     RefPtr<InjectedBundleRangeHandle> rangeHandle = InjectedBundleRangeHandle::getOrCreate(contextRef, objectRef);
     return toAPI(rangeHandle.release().leakRef());
 }
+
+WKRect WKBundleRangeHandleGetBoundingRectInWindowCoordinates(WKBundleRangeHandleRef rangeHandleRef)
+{
+    WebCore::IntRect boundingRect = toImpl(rangeHandleRef)->boundingRectInWindowCoordinates();
+    return WKRectMake(boundingRect.x(), boundingRect.y(), boundingRect.width(), boundingRect.height());
+}
+
+WKImageRef WKBundleRangeHandleCopySnapshotWithOptions(WKBundleRangeHandleRef rangeHandleRef, WKSnapshotOptions options)
+{
+    RefPtr<WebImage> image = toImpl(rangeHandleRef)->renderedImage(toSnapshotOptions(options));
+    return toAPI(image.release().leakRef());
+}
index 77335bb..c6ab5bf 100644 (file)
@@ -28,6 +28,8 @@
 
 #include <JavaScriptCore/JavaScript.h>
 #include <WebKit/WKBase.h>
+#include <WebKit/WKGeometry.h>
+#include <WebKit/WKImage.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -35,6 +37,9 @@ extern "C" {
 
 WK_EXPORT WKBundleRangeHandleRef WKBundleRangeHandleCreate(JSContextRef context, JSObjectRef object);
 
+WK_EXPORT WKRect WKBundleRangeHandleGetBoundingRectInWindowCoordinates(WKBundleRangeHandleRef rangeHandle);
+WK_EXPORT WKImageRef WKBundleRangeHandleCopySnapshotWithOptions(WKBundleRangeHandleRef rangeHandle, WKSnapshotOptions options);
+
 #ifdef __cplusplus
 }
 #endif
index a98c923..4c9f252 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "InjectedBundleNodeHandle.h"
 
+#include "InjectedBundleRangeHandle.h"
 #include "ShareableBitmap.h"
 #include "WebFrame.h"
 #include "WebFrameLoaderClient.h"
 #include <WebCore/JSNode.h>
 #include <WebCore/Node.h>
 #include <WebCore/Page.h>
+#include <WebCore/Position.h>
+#include <WebCore/Range.h>
 #include <WebCore/RenderObject.h>
+#include <WebCore/VisiblePosition.h>
 #include <wtf/HashMap.h>
 #include <wtf/NeverDestroyed.h>
 #include <wtf/text/WTFString.h>
@@ -184,6 +188,15 @@ PassRefPtr<WebImage> InjectedBundleNodeHandle::renderedImage(SnapshotOptions opt
     return image.release();
 }
 
+PassRefPtr<InjectedBundleRangeHandle> InjectedBundleNodeHandle::visibleRange() const
+{
+    VisiblePosition start = firstPositionInNode(m_node.get());
+    VisiblePosition end = lastPositionInNode(m_node.get());
+
+    RefPtr<Range> range = makeRange(start, end);
+    return InjectedBundleRangeHandle::getOrCreate(range.get());
+}
+
 void InjectedBundleNodeHandle::setHTMLInputElementValueForUser(const String& value)
 {
     if (!isHTMLInputElement(m_node.get()))
index 8dd125e..49bff0c 100644 (file)
@@ -40,6 +40,7 @@ namespace WebCore {
 
 namespace WebKit {
 
+class InjectedBundleRangeHandle;
 class InjectedBundleScriptWorld;
 class WebFrame;
 class WebImage;
@@ -61,6 +62,7 @@ public:
     WebCore::IntRect elementBounds() const;
     WebCore::IntRect renderRect(bool*) const;
     PassRefPtr<WebImage> renderedImage(SnapshotOptions);
+    PassRefPtr<InjectedBundleRangeHandle> visibleRange() const;
     void setHTMLInputElementValueForUser(const String&);
     bool isHTMLInputElementAutofilled() const;
     void setHTMLInputElementAutofilled(bool);
index 9b947d1..f63391b 100644 (file)
 #include "config.h"
 #include "InjectedBundleRangeHandle.h"
 
+#include "ShareableBitmap.h"
+#include "WebImage.h"
 #include <JavaScriptCore/APICast.h>
+#include <WebCore/Document.h>
+#include <WebCore/FloatRect.h>
+#include <WebCore/Frame.h>
+#include <WebCore/FrameSelection.h>
+#include <WebCore/FrameView.h>
+#include <WebCore/GraphicsContext.h>
+#include <WebCore/IntRect.h>
 #include <WebCore/JSRange.h>
+#include <WebCore/Page.h>
 #include <WebCore/Range.h>
+#include <WebCore/VisibleSelection.h>
 #include <wtf/HashMap.h>
 #include <wtf/NeverDestroyed.h>
 
@@ -84,4 +95,60 @@ Range* InjectedBundleRangeHandle::coreRange() const
     return m_range.get();
 }
 
+WebCore::IntRect InjectedBundleRangeHandle::boundingRectInWindowCoordinates() const
+{
+    FloatRect boundingRect = m_range->boundingRect();
+    Frame* frame = m_range->ownerDocument().frame();
+    return frame->view()->contentsToWindow(enclosingIntRect(boundingRect));
+}
+
+PassRefPtr<WebImage> InjectedBundleRangeHandle::renderedImage(SnapshotOptions options)
+{
+    Document& ownerDocument = m_range->ownerDocument();
+    Frame* frame = ownerDocument.frame();
+    if (!frame)
+        return nullptr;
+
+    FrameView* frameView = frame->view();
+    if (!frameView)
+        return nullptr;
+
+    VisibleSelection oldSelection = frame->selection().selection();
+    frame->selection().setSelection(VisibleSelection(m_range.get()));
+
+    float scaleFactor = (options & SnapshotOptionsExcludeDeviceScaleFactor) ? 1 : frame->page()->deviceScaleFactor();
+    IntRect paintRect = enclosingIntRect(m_range->boundingRect());
+    IntSize backingStoreSize = paintRect.size();
+    backingStoreSize.scale(scaleFactor);
+
+    RefPtr<ShareableBitmap> backingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
+    if (!backingStore)
+        return nullptr;
+
+    auto graphicsContext = backingStore->createGraphicsContext();
+    graphicsContext->scale(FloatSize(scaleFactor, scaleFactor));
+
+    paintRect.move(frameView->frameRect().x(), frameView->frameRect().y());
+    paintRect.move(-frameView->scrollOffset());
+
+    graphicsContext->translate(-paintRect.x(), -paintRect.y());
+
+    PaintBehavior oldPaintBehavior = frameView->paintBehavior();
+    PaintBehavior paintBehavior = oldPaintBehavior | PaintBehaviorSelectionOnly | PaintBehaviorFlattenCompositingLayers;
+    if (options & SnapshotOptionsForceBlackText)
+        paintBehavior |= PaintBehaviorForceBlackText;
+    if (options & SnapshotOptionsForceWhiteText)
+        paintBehavior |= PaintBehaviorForceWhiteText;
+
+    frameView->setPaintBehavior(paintBehavior);
+    ownerDocument.updateLayout();
+
+    frameView->paint(graphicsContext.get(), paintRect);
+    frameView->setPaintBehavior(oldPaintBehavior);
+
+    frame->selection().setSelection(oldSelection);
+
+    return WebImage::create(backingStore);
+}
+
 } // namespace WebKit
index 7695b43..17deb29 100644 (file)
 #define InjectedBundleRangeHandle_h
 
 #include "APIObject.h"
+#include "ImageOptions.h"
 #include <JavaScriptCore/JSBase.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 
 namespace WebCore {
-    class Range;
+class IntRect;
+class Range;
 }
 
 namespace WebKit {
 
 class InjectedBundleScriptWorld;
+class WebImage;
 
 class InjectedBundleRangeHandle : public API::ObjectImpl<API::Object::Type::BundleRangeHandle> {
 public:
@@ -46,6 +49,9 @@ public:
 
     virtual ~InjectedBundleRangeHandle();
 
+    WebCore::IntRect boundingRectInWindowCoordinates() const;
+    PassRefPtr<WebImage> renderedImage(SnapshotOptions);
+
     WebCore::Range* coreRange() const;
 
 private:
index 8d132df..dfbb792 100644 (file)
@@ -51,6 +51,11 @@ PassRefPtr<InjectedBundleNodeHandle> InjectedBundleHitTestResult::nodeHandle() c
     return InjectedBundleNodeHandle::getOrCreate(m_hitTestResult.innerNonSharedNode());
 }
 
+PassRefPtr<InjectedBundleNodeHandle> InjectedBundleHitTestResult::urlElementHandle() const
+{
+    return InjectedBundleNodeHandle::getOrCreate(m_hitTestResult.URLElement());
+}
+
 WebFrame* InjectedBundleHitTestResult::frame() const
 {
     Node* node = m_hitTestResult.innerNonSharedNode();
index a23d009..2c7e0e5 100644 (file)
@@ -44,7 +44,8 @@ public:
 
     const WebCore::HitTestResult& coreHitTestResult() const { return m_hitTestResult; }
 
-    PassRefPtr<InjectedBundleNodeHandle> nodeHandle() const; 
+    PassRefPtr<InjectedBundleNodeHandle> nodeHandle() const;
+    PassRefPtr<InjectedBundleNodeHandle> urlElementHandle() const;
     WebFrame* frame() const;
     WebFrame* targetFrame() const;