Title: [172780] trunk/Source
Revision
172780
Author
commit-qu...@webkit.org
Date
2014-08-19 16:33:33 -0700 (Tue, 19 Aug 2014)

Log Message

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

Patch by Peyton Randolph <prando...@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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/WebCore.exp.in (172779 => 172780)


--- trunk/Source/WebCore/WebCore.exp.in	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-08-19 23:33:33 UTC (rev 172780)
@@ -1321,6 +1321,7 @@
 __ZN7WebCore8Gradient12addColorStopEfRKNS_5ColorE
 __ZN7WebCore8GradientC1ERKNS_10FloatPointES3_
 __ZN7WebCore8GradientD1Ev
+__ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEENS0_10AnchorTypeE
 __ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEEiNS0_10AnchorTypeE
 __ZN7WebCore8Settings13gQTKitEnabledE
 __ZN7WebCore8Settings14setJavaEnabledEb

Modified: trunk/Source/WebKit2/ChangeLog (172779 => 172780)


--- trunk/Source/WebKit2/ChangeLog	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/ChangeLog	2014-08-19 23:33:33 UTC (rev 172780)
@@ -1,3 +1,32 @@
+2014-08-19  Peyton Randolph  <prando...@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  <za...@apple.com>
 
         Remove ENABLE(SUBPIXEL_LAYOUT).

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp	2014-08-19 23:33:33 UTC (rev 172780)
@@ -44,6 +44,12 @@
     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());

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h	2014-08-19 23:33:33 UTC (rev 172780)
@@ -43,6 +43,7 @@
 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);

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp	2014-08-19 23:33:33 UTC (rev 172780)
@@ -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 @@
     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());

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h	2014-08-19 23:33:33 UTC (rev 172780)
@@ -45,6 +45,7 @@
 
 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);

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp	2014-08-19 23:33:33 UTC (rev 172780)
@@ -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 @@
     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());
+}

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h	2014-08-19 23:33:33 UTC (rev 172780)
@@ -28,6 +28,8 @@
 
 #include <_javascript_Core/_javascript_.h>
 #include <WebKit/WKBase.h>
+#include <WebKit/WKGeometry.h>
+#include <WebKit/WKImage.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -35,6 +37,9 @@
 
 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

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp	2014-08-19 23:33:33 UTC (rev 172780)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "InjectedBundleNodeHandle.h"
 
+#include "InjectedBundleRangeHandle.h"
 #include "ShareableBitmap.h"
 #include "WebFrame.h"
 #include "WebFrameLoaderClient.h"
@@ -46,7 +47,10 @@
 #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 @@
     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()))

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h	2014-08-19 23:33:33 UTC (rev 172780)
@@ -40,6 +40,7 @@
 
 namespace WebKit {
 
+class InjectedBundleRangeHandle;
 class InjectedBundleScriptWorld;
 class WebFrame;
 class WebImage;
@@ -61,6 +62,7 @@
     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);

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp	2014-08-19 23:33:33 UTC (rev 172780)
@@ -26,9 +26,20 @@
 #include "config.h"
 #include "InjectedBundleRangeHandle.h"
 
+#include "ShareableBitmap.h"
+#include "WebImage.h"
 #include <_javascript_Core/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 @@
     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

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h	2014-08-19 23:33:33 UTC (rev 172780)
@@ -27,17 +27,20 @@
 #define InjectedBundleRangeHandle_h
 
 #include "APIObject.h"
+#include "ImageOptions.h"
 #include <_javascript_Core/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 @@
 
     virtual ~InjectedBundleRangeHandle();
 
+    WebCore::IntRect boundingRectInWindowCoordinates() const;
+    PassRefPtr<WebImage> renderedImage(SnapshotOptions);
+
     WebCore::Range* coreRange() const;
 
 private:

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp	2014-08-19 23:33:33 UTC (rev 172780)
@@ -51,6 +51,11 @@
     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();

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h (172779 => 172780)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h	2014-08-19 23:29:15 UTC (rev 172779)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h	2014-08-19 23:33:33 UTC (rev 172780)
@@ -44,7 +44,8 @@
 
     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;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to