Changeset 172780 in webkit


Ignore:
Timestamp:
Aug 19, 2014 4:33:33 PM (10 years ago)
Author:
commit-queue@webkit.org
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 <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:
Location:
trunk/Source
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/WebCore.exp.in

    r172749 r172780  
    13221322__ZN7WebCore8GradientC1ERKNS_10FloatPointES3_
    13231323__ZN7WebCore8GradientD1Ev
     1324__ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEENS0_10AnchorTypeE
    13241325__ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEEiNS0_10AnchorTypeE
    13251326__ZN7WebCore8Settings13gQTKitEnabledE
  • trunk/Source/WebKit2/ChangeLog

    r172758 r172780  
     12014-08-19  Peyton Randolph  <prandolph@apple.com>
     2
     3        Expose injected bundle SPI to get a node's URL element, get the visible selection range of that
     4        element, and snapshot that range
     5        https://bugs.webkit.org/show_bug.cgi?id=136076
     6
     7        Reviewed by Tim Horton.
     8
     9        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp:
     10        (WKBundleHitTestResultCopyURLElementHandle): Added.
     11        * WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h:
     12        * WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp:
     13        (WKBundleNodeHandleCopyVisibleRange): Added.
     14        * WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h:
     15        * WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp:
     16        (WKBundleRangeHandleGetBoundingRectInWindowCoordinates): Added.
     17        (WKBundleRangeHandleCopySnapshotWithOptions): Added.
     18        * WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h:
     19        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp:
     20        (WebKit::InjectedBundleNodeHandle::visibleRange): Added.
     21        * WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h:
     22        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp:
     23        (WebKit::InjectedBundleRangeHandle::boundingRectInWindowCoordinates): Added.
     24        (WebKit::InjectedBundleRangeHandle::renderedImage): Added.
     25        * WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h:
     26        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp:
     27        (WebKit::InjectedBundleHitTestResult::urlElementHandle): Added.
     28        * WebProcess/InjectedBundle/InjectedBundleHitTestResult.h:
     29
    1302014-08-19  Zalan Bujtas  <zalan@apple.com>
    231
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.cpp

    r151929 r172780  
    4343    RefPtr<InjectedBundleNodeHandle> nodeHandle = toImpl(hitTestResultRef)->nodeHandle();
    4444    return toAPI(nodeHandle.release().leakRef());
     45}
     46
     47WKBundleNodeHandleRef WKBundleHitTestResultCopyURLElementHandle(WKBundleHitTestResultRef hitTestResultRef)
     48{
     49    RefPtr<InjectedBundleNodeHandle> urlElementNodeHandle = toImpl(hitTestResultRef)->urlElementHandle();
     50    return toAPI(urlElementNodeHandle.release().leakRef());
    4551}
    4652
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleHitTestResult.h

    r168541 r172780  
    4444
    4545WK_EXPORT WKBundleNodeHandleRef WKBundleHitTestResultCopyNodeHandle(WKBundleHitTestResultRef hitTestResult);
     46WK_EXPORT WKBundleNodeHandleRef WKBundleHitTestResultCopyURLElementHandle(WKBundleHitTestResultRef hitTestResult);
    4647
    4748WK_EXPORT WKBundleFrameRef WKBundleHitTestResultGetFrame(WKBundleHitTestResultRef hitTestResult);
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandle.cpp

    r146154 r172780  
    2929
    3030#include "InjectedBundleNodeHandle.h"
     31#include "InjectedBundleRangeHandle.h"
    3132#include "WKAPICast.h"
    3233#include "WKBundleAPICast.h"
     
    6263    RefPtr<WebImage> image = toImpl(nodeHandleRef)->renderedImage(toSnapshotOptions(options));
    6364    return toAPI(image.release().leakRef());
     65}
     66
     67WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef nodeHandleRef)
     68{
     69    RefPtr<InjectedBundleRangeHandle> rangeHandle = toImpl(nodeHandleRef)->visibleRange();
     70    return toAPI(rangeHandle.release().leakRef());
    6471}
    6572
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleNodeHandlePrivate.h

    r168541 r172780  
    4646WK_EXPORT WKRect WKBundleNodeHandleGetRenderRect(WKBundleNodeHandleRef nodeHandle, bool* isReplaced);
    4747WK_EXPORT WKImageRef WKBundleNodeHandleCopySnapshotWithOptions(WKBundleNodeHandleRef nodeHandle, WKSnapshotOptions options);
     48WK_EXPORT WKBundleRangeHandleRef WKBundleNodeHandleCopyVisibleRange(WKBundleNodeHandleRef nodeHandle);
    4849
    4950/* Element Specific Operations */
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandle.cpp

    r142900 r172780  
    3131#include "WKAPICast.h"
    3232#include "WKBundleAPICast.h"
     33#include "WebImage.h"
     34#include <WebCore/IntRect.h>
    3335
    3436using namespace WebKit;
     
    4446    return toAPI(rangeHandle.release().leakRef());
    4547}
     48
     49WKRect WKBundleRangeHandleGetBoundingRectInWindowCoordinates(WKBundleRangeHandleRef rangeHandleRef)
     50{
     51    WebCore::IntRect boundingRect = toImpl(rangeHandleRef)->boundingRectInWindowCoordinates();
     52    return WKRectMake(boundingRect.x(), boundingRect.y(), boundingRect.width(), boundingRect.height());
     53}
     54
     55WKImageRef WKBundleRangeHandleCopySnapshotWithOptions(WKBundleRangeHandleRef rangeHandleRef, WKSnapshotOptions options)
     56{
     57    RefPtr<WebImage> image = toImpl(rangeHandleRef)->renderedImage(toSnapshotOptions(options));
     58    return toAPI(image.release().leakRef());
     59}
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleRangeHandlePrivate.h

    r168541 r172780  
    2929#include <JavaScriptCore/JavaScript.h>
    3030#include <WebKit/WKBase.h>
     31#include <WebKit/WKGeometry.h>
     32#include <WebKit/WKImage.h>
    3133
    3234#ifdef __cplusplus
     
    3638WK_EXPORT WKBundleRangeHandleRef WKBundleRangeHandleCreate(JSContextRef context, JSObjectRef object);
    3739
     40WK_EXPORT WKRect WKBundleRangeHandleGetBoundingRectInWindowCoordinates(WKBundleRangeHandleRef rangeHandle);
     41WK_EXPORT WKImageRef WKBundleRangeHandleCopySnapshotWithOptions(WKBundleRangeHandleRef rangeHandle, WKSnapshotOptions options);
     42
    3843#ifdef __cplusplus
    3944}
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.cpp

    r172755 r172780  
    2727#include "InjectedBundleNodeHandle.h"
    2828
     29#include "InjectedBundleRangeHandle.h"
    2930#include "ShareableBitmap.h"
    3031#include "WebFrame.h"
     
    4748#include <WebCore/Node.h>
    4849#include <WebCore/Page.h>
     50#include <WebCore/Position.h>
     51#include <WebCore/Range.h>
    4952#include <WebCore/RenderObject.h>
     53#include <WebCore/VisiblePosition.h>
    5054#include <wtf/HashMap.h>
    5155#include <wtf/NeverDestroyed.h>
     
    185189}
    186190
     191PassRefPtr<InjectedBundleRangeHandle> InjectedBundleNodeHandle::visibleRange() const
     192{
     193    VisiblePosition start = firstPositionInNode(m_node.get());
     194    VisiblePosition end = lastPositionInNode(m_node.get());
     195
     196    RefPtr<Range> range = makeRange(start, end);
     197    return InjectedBundleRangeHandle::getOrCreate(range.get());
     198}
     199
    187200void InjectedBundleNodeHandle::setHTMLInputElementValueForUser(const String& value)
    188201{
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleNodeHandle.h

    r166936 r172780  
    4141namespace WebKit {
    4242
     43class InjectedBundleRangeHandle;
    4344class InjectedBundleScriptWorld;
    4445class WebFrame;
     
    6263    WebCore::IntRect renderRect(bool*) const;
    6364    PassRefPtr<WebImage> renderedImage(SnapshotOptions);
     65    PassRefPtr<InjectedBundleRangeHandle> visibleRange() const;
    6466    void setHTMLInputElementValueForUser(const String&);
    6567    bool isHTMLInputElementAutofilled() const;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.cpp

    r161045 r172780  
    2727#include "InjectedBundleRangeHandle.h"
    2828
     29#include "ShareableBitmap.h"
     30#include "WebImage.h"
    2931#include <JavaScriptCore/APICast.h>
     32#include <WebCore/Document.h>
     33#include <WebCore/FloatRect.h>
     34#include <WebCore/Frame.h>
     35#include <WebCore/FrameSelection.h>
     36#include <WebCore/FrameView.h>
     37#include <WebCore/GraphicsContext.h>
     38#include <WebCore/IntRect.h>
    3039#include <WebCore/JSRange.h>
     40#include <WebCore/Page.h>
    3141#include <WebCore/Range.h>
     42#include <WebCore/VisibleSelection.h>
    3243#include <wtf/HashMap.h>
    3344#include <wtf/NeverDestroyed.h>
     
    8596}
    8697
     98WebCore::IntRect InjectedBundleRangeHandle::boundingRectInWindowCoordinates() const
     99{
     100    FloatRect boundingRect = m_range->boundingRect();
     101    Frame* frame = m_range->ownerDocument().frame();
     102    return frame->view()->contentsToWindow(enclosingIntRect(boundingRect));
     103}
     104
     105PassRefPtr<WebImage> InjectedBundleRangeHandle::renderedImage(SnapshotOptions options)
     106{
     107    Document& ownerDocument = m_range->ownerDocument();
     108    Frame* frame = ownerDocument.frame();
     109    if (!frame)
     110        return nullptr;
     111
     112    FrameView* frameView = frame->view();
     113    if (!frameView)
     114        return nullptr;
     115
     116    VisibleSelection oldSelection = frame->selection().selection();
     117    frame->selection().setSelection(VisibleSelection(m_range.get()));
     118
     119    float scaleFactor = (options & SnapshotOptionsExcludeDeviceScaleFactor) ? 1 : frame->page()->deviceScaleFactor();
     120    IntRect paintRect = enclosingIntRect(m_range->boundingRect());
     121    IntSize backingStoreSize = paintRect.size();
     122    backingStoreSize.scale(scaleFactor);
     123
     124    RefPtr<ShareableBitmap> backingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
     125    if (!backingStore)
     126        return nullptr;
     127
     128    auto graphicsContext = backingStore->createGraphicsContext();
     129    graphicsContext->scale(FloatSize(scaleFactor, scaleFactor));
     130
     131    paintRect.move(frameView->frameRect().x(), frameView->frameRect().y());
     132    paintRect.move(-frameView->scrollOffset());
     133
     134    graphicsContext->translate(-paintRect.x(), -paintRect.y());
     135
     136    PaintBehavior oldPaintBehavior = frameView->paintBehavior();
     137    PaintBehavior paintBehavior = oldPaintBehavior | PaintBehaviorSelectionOnly | PaintBehaviorFlattenCompositingLayers;
     138    if (options & SnapshotOptionsForceBlackText)
     139        paintBehavior |= PaintBehaviorForceBlackText;
     140    if (options & SnapshotOptionsForceWhiteText)
     141        paintBehavior |= PaintBehaviorForceWhiteText;
     142
     143    frameView->setPaintBehavior(paintBehavior);
     144    ownerDocument.updateLayout();
     145
     146    frameView->paint(graphicsContext.get(), paintRect);
     147    frameView->setPaintBehavior(oldPaintBehavior);
     148
     149    frame->selection().setSelection(oldSelection);
     150
     151    return WebImage::create(backingStore);
     152}
     153
    87154} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/DOM/InjectedBundleRangeHandle.h

    r160384 r172780  
    2828
    2929#include "APIObject.h"
     30#include "ImageOptions.h"
    3031#include <JavaScriptCore/JSBase.h>
    3132#include <wtf/PassRefPtr.h>
     
    3334
    3435namespace WebCore {
    35     class Range;
     36class IntRect;
     37class Range;
    3638}
    3739
     
    3941
    4042class InjectedBundleScriptWorld;
     43class WebImage;
    4144
    4245class InjectedBundleRangeHandle : public API::ObjectImpl<API::Object::Type::BundleRangeHandle> {
     
    4649
    4750    virtual ~InjectedBundleRangeHandle();
     51
     52    WebCore::IntRect boundingRectInWindowCoordinates() const;
     53    PassRefPtr<WebImage> renderedImage(SnapshotOptions);
    4854
    4955    WebCore::Range* coreRange() const;
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.cpp

    r166262 r172780  
    5050{
    5151    return InjectedBundleNodeHandle::getOrCreate(m_hitTestResult.innerNonSharedNode());
     52}
     53
     54PassRefPtr<InjectedBundleNodeHandle> InjectedBundleHitTestResult::urlElementHandle() const
     55{
     56    return InjectedBundleNodeHandle::getOrCreate(m_hitTestResult.URLElement());
    5257}
    5358
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundleHitTestResult.h

    r160384 r172780  
    4545    const WebCore::HitTestResult& coreHitTestResult() const { return m_hitTestResult; }
    4646
    47     PassRefPtr<InjectedBundleNodeHandle> nodeHandle() const;
     47    PassRefPtr<InjectedBundleNodeHandle> nodeHandle() const;
     48    PassRefPtr<InjectedBundleNodeHandle> urlElementHandle() const;
    4849    WebFrame* frame() const;
    4950    WebFrame* targetFrame() const;
Note: See TracChangeset for help on using the changeset viewer.