Title: [198739] trunk/Source
Revision
198739
Author
timo...@apple.com
Date
2016-03-28 08:57:37 -0700 (Mon, 28 Mar 2016)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (198738 => 198739)


--- trunk/Source/WebCore/ChangeLog	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebCore/ChangeLog	2016-03-28 15:57:37 UTC (rev 198739)
@@ -1,3 +1,15 @@
+2016-03-24  Timothy Hatcher  <timo...@apple.com>
+
+        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.
+
+        * 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.
+
 2016-03-18  Timothy Hatcher  <timo...@apple.com>
 
         Web Automation: Add Automation protocol commands to resolve frames as handles

Modified: trunk/Source/WebCore/dom/Element.h (198738 => 198739)


--- trunk/Source/WebCore/dom/Element.h	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebCore/dom/Element.h	2016-03-28 15:57:37 UTC (rev 198739)
@@ -124,7 +124,7 @@
     unsigned findAttributeIndexByName(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->findAttributeIndexByName(name, shouldIgnoreAttributeCase); }
 
     void scrollIntoView(bool alignToTop = true);
-    void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
+    WEBCORE_EXPORT void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
     WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
 
     void scrollByLines(int lines);
@@ -157,7 +157,7 @@
 
     Ref<ClientRectList> getClientRects();
     Ref<ClientRect> getBoundingClientRect();
-    
+
     // Returns the absolute bounding box translated into client coordinates.
     WEBCORE_EXPORT IntRect clientRect() const;
     // Returns the absolute bounding box translated into screen coordinates.

Modified: trunk/Source/WebCore/platform/ScrollView.h (198738 => 198739)


--- trunk/Source/WebCore/platform/ScrollView.h	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebCore/platform/ScrollView.h	2016-03-28 15:57:37 UTC (rev 198739)
@@ -286,7 +286,7 @@
 
     WEBCORE_EXPORT IntPoint rootViewToContents(const IntPoint&) const;
     WEBCORE_EXPORT IntPoint contentsToRootView(const IntPoint&) const;
-    IntRect rootViewToContents(const IntRect&) const;
+    WEBCORE_EXPORT IntRect rootViewToContents(const IntRect&) const;
     WEBCORE_EXPORT IntRect contentsToRootView(const IntRect&) const;
 
     IntPoint viewToContents(const IntPoint&) const;

Modified: trunk/Source/WebKit2/ChangeLog (198738 => 198739)


--- trunk/Source/WebKit2/ChangeLog	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/ChangeLog	2016-03-28 15:57:37 UTC (rev 198739)
@@ -1,3 +1,27 @@
+2016-03-24  Timothy Hatcher  <timo...@apple.com>
+
+        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.
+
+        * 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.
+
 2016-03-18  Timothy Hatcher  <timo...@apple.com>
 
         Web Automation: Add Automation protocol commands to resolve frames as handles

Modified: trunk/Source/WebKit2/UIProcess/Automation/Automation.json (198738 => 198739)


--- trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/UIProcess/Automation/Automation.json	2016-03-28 15:57:37 UTC (rev 198739)
@@ -3,6 +3,30 @@
     "description": "Automation domain exposes commands for automating user interactions with the browser.",
     "types": [
         {
+            "id": "Point",
+            "type": "object",
+            "properties": [
+                { "name": "x", "type": "number" },
+                { "name": "y", "type": "number" }
+            ]
+        },
+        {
+            "id": "Size",
+            "type": "object",
+            "properties": [
+                { "name": "width", "type": "number" },
+                { "name": "height", "type": "number" }
+            ]
+        },
+        {
+            "id": "Rect",
+            "type": "object",
+            "properties": [
+                { "name": "origin", "$ref": "Point" },
+                { "name": "size", "$ref": "Size" }
+            ]
+        },
+        {
             "id": "BrowsingContextHandle",
             "type": "string",
             "description": "An opaque identifier for a browsing context."
@@ -152,6 +176,21 @@
                 { "name": "result", "$ref": "FrameHandle", "description": "The <code>FrameHandle</code> for the requested frame." }
             ],
             "async": true
+        },
+        {
+            "name": "computeElementLayout",
+            "description": "Computes the layout for an element.",
+            "parameters": [
+                { "name": "browsingContextHandle", "$ref": "BrowsingContextHandle", "description": "The handle for the browsing context the frame is located." },
+                { "name": "frameHandle", "$ref": "FrameHandle", "description": "The handle for the frame that contains the element." },
+                { "name": "nodeHandle", "$ref": "NodeHandle", "description": "The handle of the element to use." },
+                { "name": "scrollIntoViewIfNeeded", "optional": true, "type": "boolean", "description": "If the element should be scrolled into view before computing its layout." },
+                { "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." }
+            ],
+            "returns": [
+                { "name": "rect", "$ref": "Rect", "description": "The layout rect for the requested element. Specified in page or viewport coordinates based on the useViewportCoordinates parameter." }
+            ],
+            "async": true
         }
     ]
 }

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp (198738 => 198739)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.cpp	2016-03-28 15:57:37 UTC (rev 198739)
@@ -417,4 +417,52 @@
         callback->sendSuccess(handleForWebFrameID(frameID));
 }
 
+void WebAutomationSession::computeElementLayout(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* optionalUseViewportCoordinates, Ref<ComputeElementLayoutCallback>&& callback)
+{
+    WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
+    if (!page)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(WindowNotFound);
+
+    WebFrameProxy* frame = webFrameProxyForHandle(frameHandle, *page);
+    if (!frame)
+        FAIL_WITH_PREDEFINED_ERROR_MESSAGE(FrameNotFound);
+
+    uint64_t callbackID = m_nextComputeElementLayoutCallbackID++;
+    m_computeElementLayoutCallbacks.set(callbackID, WTFMove(callback));
+
+    bool scrollIntoViewIfNeeded = optionalScrollIntoViewIfNeeded ? *optionalScrollIntoViewIfNeeded : false;
+    bool useViewportCoordinates = optionalUseViewportCoordinates ? *optionalUseViewportCoordinates : false;
+
+    page->process().send(Messages::WebAutomationSessionProxy::ComputeElementLayout(frame->frameID(), nodeHandle, scrollIntoViewIfNeeded, useViewportCoordinates, callbackID), 0);
+}
+
+void WebAutomationSession::didComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, const String& errorType)
+{
+    auto callback = m_computeElementLayoutCallbacks.take(callbackID);
+    if (!callback)
+        return;
+
+    if (!errorType.isEmpty()) {
+        callback->sendFailure(errorType);
+        return;
+    }
+
+    auto originObject = Inspector::Protocol::Automation::Point::create()
+        .setX(rect.x())
+        .setY(rect.y())
+        .release();
+
+    auto sizeObject = Inspector::Protocol::Automation::Size::create()
+        .setWidth(rect.width())
+        .setHeight(rect.height())
+        .release();
+
+    auto rectObject = Inspector::Protocol::Automation::Rect::create()
+        .setOrigin(WTFMove(originObject))
+        .setSize(WTFMove(sizeObject))
+        .release();
+
+    callback->sendSuccess(WTFMove(rectObject));
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h (198738 => 198739)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.h	2016-03-28 15:57:37 UTC (rev 198739)
@@ -44,6 +44,10 @@
 class FrontendRouter;
 }
 
+namespace WebCore {
+class IntRect;
+}
+
 namespace WebKit {
 
 class WebAutomationSessionClient;
@@ -90,6 +94,7 @@
     void evaluateJavaScriptFunction(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const String& function, const Inspector::InspectorArray& arguments, bool expectsImplicitCallbackArgument, Ref<Inspector::AutomationBackendDispatcherHandler::EvaluateJavaScriptFunctionCallback>&&) override;
     void resolveChildFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String* optionalFrameHandle, const int* optionalOrdinal, const String* optionalName, const String* optionalNodeHandle, Ref<ResolveChildFrameHandleCallback>&&) override;
     void resolveParentFrameHandle(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, Ref<ResolveParentFrameHandleCallback>&&) override;
+    void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const bool* useViewportCoordinates, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
 
 private:
     WebPageProxy* webPageProxyForHandle(const String&);
@@ -106,6 +111,7 @@
     void didEvaluateJavaScriptFunction(uint64_t callbackID, const String& result, const String& errorType);
     void didResolveChildFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
     void didResolveParentFrame(uint64_t callbackID, uint64_t frameID, const String& errorType);
+    void didComputeElementLayout(uint64_t callbackID, WebCore::IntRect, const String& errorType);
 
     WebProcessPool* m_processPool { nullptr };
 
@@ -131,6 +137,9 @@
     uint64_t m_nextResolveParentFrameCallbackID { 1 };
     HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ResolveParentFrameHandleCallback>> m_resolveParentFrameHandleCallbacks;
 
+    uint64_t m_nextComputeElementLayoutCallbackID { 1 };
+    HashMap<uint64_t, RefPtr<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>> m_computeElementLayoutCallbacks;
+
 #if ENABLE(REMOTE_INSPECTOR)
     Inspector::FrontendChannel* m_remoteChannel { nullptr };
 #endif

Modified: trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in (198738 => 198739)


--- trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/UIProcess/Automation/WebAutomationSession.messages.in	2016-03-28 15:57:37 UTC (rev 198739)
@@ -25,4 +25,6 @@
 
     DidResolveChildFrame(uint64_t callbackID, uint64_t frameID, String errorType)
     DidResolveParentFrame(uint64_t callbackID, uint64_t frameID, String errorType)
+
+    DidComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, String errorType)
 }

Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp (198738 => 198739)


--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.cpp	2016-03-28 15:57:37 UTC (rev 198739)
@@ -41,6 +41,7 @@
 #include <WebCore/DOMWindow.h>
 #include <WebCore/Frame.h>
 #include <WebCore/FrameTree.h>
+#include <WebCore/FrameView.h>
 #include <WebCore/HTMLFrameElementBase.h>
 #include <WebCore/JSElement.h>
 #include <WebCore/MainFrame.h>
@@ -407,4 +408,45 @@
     coreDOMWindow->focus(true);
 }
 
+void WebAutomationSessionProxy::computeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
+{
+    String frameNotFoundErrorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
+    String nodeNotFoundErrorType = Inspector::Protocol::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::NodeNotFound);
+
+    WebFrame* frame = WebProcess::singleton().webFrame(frameID);
+    if (!frame) {
+        WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), frameNotFoundErrorType), 0);
+        return;
+    }
+
+    WebCore::Element* coreElement = elementForNodeHandle(*frame, nodeHandle);
+    if (!coreElement) {
+        WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), nodeNotFoundErrorType), 0);
+        return;
+    }
+
+    if (scrollIntoViewIfNeeded)
+        coreElement->scrollIntoViewIfNeeded(false);
+
+    WebCore::IntRect rect = coreElement->clientRect();
+
+    if (!useViewportCoordinates) {
+        WebCore::Frame* coreFrame = frame->coreFrame();
+        if (!coreFrame) {
+            WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), frameNotFoundErrorType), 0);
+            return;
+        }
+
+        WebCore::FrameView *coreFrameView = coreFrame->view();
+        if (!coreFrameView) {
+            WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, WebCore::IntRect(), frameNotFoundErrorType), 0);
+            return;
+        }
+
+        rect = coreFrameView->rootViewToContents(rect);
+    }
+
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, rect, emptyString()), 0);
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h (198738 => 198739)


--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.h	2016-03-28 15:57:37 UTC (rev 198739)
@@ -63,6 +63,7 @@
     void resolveChildFrameWithName(uint64_t frameID, const String& name, uint64_t callbackID);
     void resolveParentFrame(uint64_t frameID, uint64_t callbackID);
     void focusFrame(uint64_t frameID);
+    void computeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID);
 
     String m_sessionIdentifier;
 

Modified: trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in (198738 => 198739)


--- trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in	2016-03-28 15:57:23 UTC (rev 198738)
+++ trunk/Source/WebKit2/WebProcess/Automation/WebAutomationSessionProxy.messages.in	2016-03-28 15:57:37 UTC (rev 198739)
@@ -29,4 +29,6 @@
     ResolveParentFrame(uint64_t frameID, uint64_t callbackID)
 
     FocusFrame(uint64_t frameID)
+
+    ComputeElementLayout(uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to