Changeset 198739 in webkit


Ignore:
Timestamp:
Mar 28, 2016 8:57:37 AM (8 years ago)
Author:
timothy@apple.com
Message:

Web Automation: Add commands to compute layout of an element

https://bugs.webkit.org/show_bug.cgi?id=155841
rdar://problem/25340075

Reviewed by Brian Burg.

Source/WebCore:

  • dom/Element.h: Mark scrollIntoViewIfNeeded() method as exported so WK2 can use it.
  • platform/ScrollView.h: Mark rootViewToContents(IntRect) method as exported so WK2 can use it.

Source/WebKit2:

  • UIProcess/Automation/Automation.json: Added computeElementLayout.
  • UIProcess/Automation/WebAutomationSession.cpp:

(WebKit::WebAutomationSession::computeElementLayout): Added.
(WebKit::WebAutomationSession::didComputeElementLayout): Added.

  • UIProcess/Automation/WebAutomationSession.h:
  • UIProcess/Automation/WebAutomationSession.messages.in:

(DidComputeElementLayout): Added.

  • WebProcess/Automation/WebAutomationSessionProxy.cpp:

(WebKit::WebAutomationSessionProxy::computeElementLayout): Added.

  • WebProcess/Automation/WebAutomationSessionProxy.h:
  • WebProcess/Automation/WebAutomationSessionProxy.messages.in:

(ComputeElementLayout): Added.

Location:
trunk/Source
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r198738 r198739  
     12016-03-24  Timothy Hatcher  <timothy@apple.com>
     2
     3        Web Automation: Add commands to compute layout of an element
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=155841
     6        rdar://problem/25340075
     7
     8        Reviewed by Brian Burg.
     9
     10        * dom/Element.h: Mark scrollIntoViewIfNeeded() method as exported so WK2 can use it.
     11        * platform/ScrollView.h: Mark rootViewToContents(IntRect) method as exported so WK2 can use it.
     12
    1132016-03-18  Timothy Hatcher  <timothy@apple.com>
    214
  • trunk/Source/WebCore/dom/Element.h

    r197764 r198739  
    125125
    126126    void scrollIntoView(bool alignToTop = true);
    127     void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
     127    WEBCORE_EXPORT void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
    128128    WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
    129129
     
    158158    Ref<ClientRectList> getClientRects();
    159159    Ref<ClientRect> getBoundingClientRect();
    160    
     160
    161161    // Returns the absolute bounding box translated into client coordinates.
    162162    WEBCORE_EXPORT IntRect clientRect() const;
  • trunk/Source/WebCore/platform/ScrollView.h

    r198560 r198739  
    287287    WEBCORE_EXPORT IntPoint rootViewToContents(const IntPoint&) const;
    288288    WEBCORE_EXPORT IntPoint contentsToRootView(const IntPoint&) const;
    289     IntRect rootViewToContents(const IntRect&) const;
     289    WEBCORE_EXPORT IntRect rootViewToContents(const IntRect&) const;
    290290    WEBCORE_EXPORT IntRect contentsToRootView(const IntRect&) const;
    291291
  • trunk/Source/WebKit2/ChangeLog

    r198738 r198739  
     12016-03-24  Timothy Hatcher  <timothy@apple.com>
     2
     3        Web Automation: Add commands to compute layout of an element
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=155841
     6        rdar://problem/25340075
     7
     8        Reviewed by Brian Burg.
     9
     10        * UIProcess/Automation/Automation.json: Added computeElementLayout.
     11
     12        * UIProcess/Automation/WebAutomationSession.cpp:
     13        (WebKit::WebAutomationSession::computeElementLayout): Added.
     14        (WebKit::WebAutomationSession::didComputeElementLayout): Added.
     15        * UIProcess/Automation/WebAutomationSession.h:
     16        * UIProcess/Automation/WebAutomationSession.messages.in:
     17        (DidComputeElementLayout): Added.
     18
     19        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
     20        (WebKit::WebAutomationSessionProxy::computeElementLayout): Added.
     21        * WebProcess/Automation/WebAutomationSessionProxy.h:
     22        * WebProcess/Automation/WebAutomationSessionProxy.messages.in:
     23        (ComputeElementLayout): Added.
     24
    1252016-03-18  Timothy Hatcher  <timothy@apple.com>
    226
  • trunk/Source/WebKit2/UIProcess/Automation/Automation.json

    r198738 r198739  
    33    "description": "Automation domain exposes commands for automating user interactions with the browser.",
    44    "types": [
     5        {
     6            "id": "Point",
     7            "type": "object",
     8            "properties": [
     9                { "name": "x", "type": "number" },
     10                { "name": "y", "type": "number" }
     11            ]
     12        },
     13        {
     14            "id": "Size",
     15            "type": "object",
     16            "properties": [
     17                { "name": "width", "type": "number" },
     18                { "name": "height", "type": "number" }
     19            ]
     20        },
     21        {
     22            "id": "Rect",
     23            "type": "object",
     24            "properties": [
     25                { "name": "origin", "$ref": "Point" },
     26                { "name": "size", "$ref": "Size" }
     27            ]
     28        },
    529        {
    630            "id": "BrowsingContextHandle",
     
    153177            ],
    154178            "async": true
     179        },
     180        {
     181            "name": "computeElementLayout",
     182            "description": "Computes the layout for an element.",
     183            "parameters": [
     184                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context the frame is located." },
     185                { "name": "frameHandle", "$ref": "FrameHandle", "description": "The handle for the frame that contains the element." },
     186                { "name": "nodeHandle", "$ref": "NodeHandle", "description": "The handle of the element to use." },
     187                { "name": "scrollIntoViewIfNeeded", "optional": true, "type": "boolean", "description": "If the element should be scrolled into view before computing its layout." },
     188                { "name": "useViewportCoordinates", "optional": true, "type": "boolean", "description": "If the result coordinates should be represented as viewport coordinates or not. Defaults to false, which means coordinates should be represented as page coordinates." }
     189            ],
     190            "returns": [
     191                { "name": "rect", "$ref": "Rect", "description": "The layout rect for the requested element. Specified in page or viewport coordinates based on the useViewportCoordinates parameter." }
     192            ],
     193            "async": true
    155194        }
    156195    ]
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp

    r198738 r198739  
    418418}
    419419
     420void WebAutomationSession::computeElementLayout(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* optionalUseViewportCoordinates, Ref<ComputeElementLayoutCallback>&& callback)
     421{
     422    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     423    if (!page)
     424        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
     425
     426    WebFrameProxy* frame = webFrameProxyForHandle(frameHandle, *page);
     427    if (!frame)
     428        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(FrameNotFound);
     429
     430    uint64_t callbackID = m_nextComputeElementLayoutCallbackID++;
     431    m_computeElementLayoutCallbacks.set(callbackID, WTFMove(callback));
     432
     433    bool scrollIntoViewIfNeeded = optionalScrollIntoViewIfNeeded ? *optionalScrollIntoViewIfNeeded : false;
     434    bool useViewportCoordinates = optionalUseViewportCoordinates ? *optionalUseViewportCoordinates : false;
     435
     436    page->process().send(Messages::WebAutomationSessionProxy::ComputeElementLayout(frame->frameID(), nodeHandle, scrollIntoViewIfNeeded, useViewportCoordinates, callbackID), 0);
     437}
     438
     439void WebAutomationSession::didComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, const String& errorType)
     440{
     441    auto callback = m_computeElementLayoutCallbacks.take(callbackID);
     442    if (!callback)
     443        return;
     444
     445    if (!errorType.isEmpty()) {
     446        callback->sendFailure(errorType);
     447        return;
     448    }
     449
     450    auto originObject = Inspector::Protocol::Automation::Point::create()
     451        .setX(rect.x())
     452        .setY(rect.y())
     453        .release();
     454
     455    auto sizeObject = Inspector::Protocol::Automation::Size::create()
     456        .setWidth(rect.width())
     457        .setHeight(rect.height())
     458        .release();
     459
     460    auto rectObject = Inspector::Protocol::Automation::Rect::create()
     461        .setOrigin(WTFMove(originObject))
     462        .setSize(WTFMove(sizeObject))
     463        .release();
     464
     465    callback->sendSuccess(WTFMove(rectObject));
     466}
     467
    420468} // namespace WebKit
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h

    r198738 r198739  
    4343class BackendDispatcher;
    4444class FrontendRouter;
     45}
     46
     47namespace WebCore {
     48class IntRect;
    4549}
    4650
     
    9195    void resolveChildFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref<ResolveChildFrameHandleCallback>&&) override;
    9296    void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
     97    void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
    9398
    9499private:
     
    107112    void didResolveChildFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
    108113    void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
     114    void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, const String& errorType);
    109115
    110116    WebProcessPool* m_processPool { nullptr };
     
    132138    HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ResolveParentFrameHandleCallback>> m_resolveParentFrameHandleCallbacks;
    133139
     140    uint64_t m_nextComputeElementLayoutCallbackID { 1 };
     141    HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>> m_computeElementLayoutCallbacks;
     142
    134143#if ENABLE(REMOTE_INSPECTOR)
    135144    Inspector::FrontendChannel* m_remoteChannel { nullptr };
  • trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in

    r198738 r198739  
    2626    DidResolveChildFrame(uint64_t callbackID, uint64_t frameID, String errorType)
    2727    DidResolveParentFrame(uint64_t callbackID, uint64_t frameID, String errorType)
     28
     29    DidComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, String errorType)
    2830}
  • trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp

    r198738 r198739  
    4242#include <WebCore/Frame.h>
    4343#include <WebCore/FrameTree.h>
     44#include <WebCore/FrameView.h>
    4445#include <WebCore/HTMLFrameElementBase.h>
    4546#include <WebCore/JSElement.h>
     
    408409}
    409410
     411void WebAutomationSessionProxy::computeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
     412{
     413    String frameNotFoundErrorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
     414    String nodeNotFoundErrorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::NodeNotFound);
     415
     416    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     417    if (!frame) {
     418        WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), frameNotFoundErrorType), 0);
     419        return;
     420    }
     421
     422    WebCore::Element* coreElement = elementForNodeHandle(*frame, nodeHandle);
     423    if (!coreElement) {
     424        WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), nodeNotFoundErrorType), 0);
     425        return;
     426    }
     427
     428    if (scrollIntoViewIfNeeded)
     429        coreElement->scrollIntoViewIfNeeded(false);
     430
     431    WebCore::IntRect rect = coreElement->clientRect();
     432
     433    if (!useViewportCoordinates) {
     434        WebCore::Frame* coreFrame = frame->coreFrame();
     435        if (!coreFrame) {
     436            WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), frameNotFoundErrorType), 0);
     437            return;
     438        }
     439
     440        WebCore::FrameView *coreFrameView = coreFrame->view();
     441        if (!coreFrameView) {
     442            WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), frameNotFoundErrorType), 0);
     443            return;
     444        }
     445
     446        rect = coreFrameView->rootViewToContents(rect);
     447    }
     448
     449    WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, rect, emptyString()), 0);
     450}
     451
    410452} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h

    r198738 r198739  
    6464    void resolveParentFrame(uint64_t frameID, uint64_t callbackID);
    6565    void focusFrame(uint64_t frameID);
     66    void computeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID);
    6667
    6768    String m_sessionIdentifier;
  • trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in

    r198738 r198739  
    3030
    3131    FocusFrame(uint64_t frameID)
     32
     33    ComputeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
    3234}
Note: See TracChangeset for help on using the changeset viewer.