Title: [224789] trunk/Source
Revision
224789
Author
[email protected]
Date
2017-11-13 15:21:31 -0800 (Mon, 13 Nov 2017)

Log Message

Web Automation: inViewCenterPoint should not include topContentInset when computed in viewport coordinates
https://bugs.webkit.org/show_bug.cgi?id=179129
<rdar://problem/35297038>

Reviewed by Simon Fraser.

Source/WebCore:

Add or export some helpers needed to compute element layout for WebDriver.

* dom/Element.h: Export the non-DOM version of getClientBounds().
* page/FrameView.h:
* page/FrameView.cpp:
(WebCore::FrameView::clientToDocumentRect const):
Added. This does the same thing as clientToDocumentPoint. Export it, too.

Source/WebDriver:

Adjust code to use the proper coordinate system when requesting element layout.

* Session.cpp:
(WebDriver::Session::computeElementLayout):

Source/WebKit:

When computing the in view center point per W3C specification, the top content inset
is inadvertently added back in when converting to the root view coordinate system.

This patch reworks the protocol command so that it explicitly requests a coordinate
system, with options for "Page" (root / contents), "LayoutViewport", and "VisualViewport".
The latter is not implemented in this patch, since it is intended for use on iOS someday.

* UIProcess/Automation/Automation.json:
Change usesViewport to CoordinateSystem.
Add a new coordinate system enum type and use it.
Fix relevant comments for Automation.computElementLayout.

* UIProcess/Automation/WebAutomationSession.h:
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::protocolStringToCoordinateSystem):
(WebKit::WebAutomationSession::computeElementLayout):
Parse the requested coordinate system and send it in the message to the web process.

* WebKit.xcodeproj/project.pbxproj:
* WebProcess/Automation/WebAutomationSessionProxy.messages.in:
* WebProcess/Automation/WebAutomationSessionProxy.h:
* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::WebAutomationSessionProxy::computeElementLayout):
Rework the implementation. Get the element bounds and in-view center point in
client coordinates and convert back to root view coordinates for CoordinateSystem::Page.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (224788 => 224789)


--- trunk/Source/WebCore/ChangeLog	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebCore/ChangeLog	2017-11-13 23:21:31 UTC (rev 224789)
@@ -1,3 +1,19 @@
+2017-11-07  Brian Burg  <[email protected]>
+
+        Web Automation: inViewCenterPoint should not include topContentInset when computed in viewport coordinates
+        https://bugs.webkit.org/show_bug.cgi?id=179129
+        <rdar://problem/35297038>
+
+        Reviewed by Simon Fraser.
+
+        Add or export some helpers needed to compute element layout for WebDriver.
+
+        * dom/Element.h: Export the non-DOM version of getClientBounds().
+        * page/FrameView.h:
+        * page/FrameView.cpp:
+        (WebCore::FrameView::clientToDocumentRect const):
+        Added. This does the same thing as clientToDocumentPoint. Export it, too.
+
 2017-11-13  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Include a NetworkAgent in ServiceWorkers for network debugging

Modified: trunk/Source/WebCore/dom/Element.h (224788 => 224789)


--- trunk/Source/WebCore/dom/Element.h	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebCore/dom/Element.h	2017-11-13 23:21:31 UTC (rev 224789)
@@ -171,7 +171,7 @@
 
     WEBCORE_EXPORT IntRect boundsInRootViewSpace();
 
-    FloatRect boundingClientRect();
+    WEBCORE_EXPORT FloatRect boundingClientRect();
 
     WEBCORE_EXPORT Ref<DOMRectList> getClientRects();
     Ref<DOMRect> getBoundingClientRect();

Modified: trunk/Source/WebCore/page/FrameView.cpp (224788 => 224789)


--- trunk/Source/WebCore/page/FrameView.cpp	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebCore/page/FrameView.cpp	2017-11-13 23:21:31 UTC (rev 224789)
@@ -4473,6 +4473,12 @@
     return p;
 }
 
+FloatRect FrameView::clientToDocumentRect(FloatRect rect) const
+{
+    rect.move(-documentToClientOffset());
+    return rect;
+}
+
 FloatPoint FrameView::clientToDocumentPoint(FloatPoint point) const
 {
     point.move(-documentToClientOffset());

Modified: trunk/Source/WebCore/page/FrameView.h (224788 => 224789)


--- trunk/Source/WebCore/page/FrameView.h	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebCore/page/FrameView.h	2017-11-13 23:21:31 UTC (rev 224789)
@@ -466,6 +466,7 @@
     FloatSize documentToClientOffset() const;
     FloatRect documentToClientRect(FloatRect) const;
     FloatPoint documentToClientPoint(FloatPoint) const;
+    WEBCORE_EXPORT FloatRect clientToDocumentRect(FloatRect) const;
     WEBCORE_EXPORT FloatPoint clientToDocumentPoint(FloatPoint) const;
 
     FloatRect layoutViewportToAbsoluteRect(FloatRect) const;

Modified: trunk/Source/WebDriver/ChangeLog (224788 => 224789)


--- trunk/Source/WebDriver/ChangeLog	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebDriver/ChangeLog	2017-11-13 23:21:31 UTC (rev 224789)
@@ -1,3 +1,16 @@
+2017-11-07  Brian Burg  <[email protected]>
+
+        Web Automation: inViewCenterPoint should not include topContentInset when computed in viewport coordinates
+        https://bugs.webkit.org/show_bug.cgi?id=179129
+        <rdar://problem/35297038>
+
+        Reviewed by Simon Fraser.
+
+        Adjust code to use the proper coordinate system when requesting element layout.
+
+        * Session.cpp:
+        (WebDriver::Session::computeElementLayout):
+
 2017-11-09  Carlos Garcia Campos  <[email protected]>
 
         WebDriver: WebDriverService::matchCapabilities should follow the spec

Modified: trunk/Source/WebDriver/Session.cpp (224788 => 224789)


--- trunk/Source/WebDriver/Session.cpp	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebDriver/Session.cpp	2017-11-13 23:21:31 UTC (rev 224789)
@@ -825,7 +825,7 @@
     parameters->setString(ASCIILiteral("frameHandle"), m_currentBrowsingContext.value());
     parameters->setString(ASCIILiteral("nodeHandle"), elementID);
     parameters->setBoolean(ASCIILiteral("scrollIntoViewIfNeeded"), options.contains(ElementLayoutOption::ScrollIntoViewIfNeeded));
-    parameters->setBoolean(ASCIILiteral("useViewportCoordinates"), options.contains(ElementLayoutOption::UseViewportCoordinates));
+    parameters->setString(ASCIILiteral("coordinateSystem"), options.contains(ElementLayoutOption::UseViewportCoordinates) ? ASCIILiteral("LayoutViewport") : ASCIILiteral("Page"));
     m_host->sendCommandToBackend(ASCIILiteral("computeElementLayout"), WTFMove(parameters), [this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler)](SessionHost::CommandResponse&& response) mutable {
         if (response.isError || !response.responseObject) {
             completionHandler(std::nullopt, std::nullopt, false, WTFMove(response.responseObject));

Modified: trunk/Source/WebKit/ChangeLog (224788 => 224789)


--- trunk/Source/WebKit/ChangeLog	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/ChangeLog	2017-11-13 23:21:31 UTC (rev 224789)
@@ -1,3 +1,37 @@
+2017-11-07  Brian Burg  <[email protected]>
+
+        Web Automation: inViewCenterPoint should not include topContentInset when computed in viewport coordinates
+        https://bugs.webkit.org/show_bug.cgi?id=179129
+        <rdar://problem/35297038>
+
+        Reviewed by Simon Fraser.
+
+        When computing the in view center point per W3C specification, the top content inset
+        is inadvertently added back in when converting to the root view coordinate system.
+
+        This patch reworks the protocol command so that it explicitly requests a coordinate
+        system, with options for "Page" (root / contents), "LayoutViewport", and "VisualViewport".
+        The latter is not implemented in this patch, since it is intended for use on iOS someday.
+
+        * UIProcess/Automation/Automation.json:
+        Change usesViewport to CoordinateSystem.
+        Add a new coordinate system enum type and use it.
+        Fix relevant comments for Automation.computElementLayout.
+
+        * UIProcess/Automation/WebAutomationSession.h:
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::protocolStringToCoordinateSystem):
+        (WebKit::WebAutomationSession::computeElementLayout):
+        Parse the requested coordinate system and send it in the message to the web process.
+
+        * WebKit.xcodeproj/project.pbxproj:
+        * WebProcess/Automation/WebAutomationSessionProxy.messages.in:
+        * WebProcess/Automation/WebAutomationSessionProxy.h:
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::WebAutomationSessionProxy::computeElementLayout):
+        Rework the implementation. Get the element bounds and in-view center point in
+        client coordinates and convert back to root view coordinates for CoordinateSystem::Page.
+
 2017-11-08  Keith Miller  <[email protected]>
 
         Async iteration should only fetch the next method once and add feature flag

Added: trunk/Source/WebKit/Shared/CoordinateSystem.h (0 => 224789)


--- trunk/Source/WebKit/Shared/CoordinateSystem.h	                        (rev 0)
+++ trunk/Source/WebKit/Shared/CoordinateSystem.h	2017-11-13 23:21:31 UTC (rev 224789)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 Apple Inc.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#pragma once
+
+#include <wtf/EnumTraits.h>
+
+namespace WebKit {
+
+enum class CoordinateSystem {
+    Page = 0,
+    LayoutViewport,
+    VisualViewport,
+};
+
+} // namespace WebKit
+
+namespace WTF {
+
+template<> struct EnumTraits<WebKit::CoordinateSystem> {
+    using values = EnumValues<
+    WebKit::CoordinateSystem,
+    WebKit::CoordinateSystem::Page,
+    WebKit::CoordinateSystem::LayoutViewport,
+    WebKit::CoordinateSystem::VisualViewport
+    >;
+};
+
+} // namespace WTF

Modified: trunk/Source/WebKit/UIProcess/Automation/Automation.json (224788 => 224789)


--- trunk/Source/WebKit/UIProcess/Automation/Automation.json	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/UIProcess/Automation/Automation.json	2017-11-13 23:21:31 UTC (rev 224789)
@@ -27,6 +27,16 @@
             ]
         },
         {
+            "id": "CoordinateSystem",
+            "type": "string",
+            "description": "The coordinate system in which rects, points, and sizes are to be interpreted.",
+            "enum": [
+                "Page",
+                "LayoutViewport",
+                "VisualViewport"
+            ]
+        },
+        {
             "id": "BrowsingContextHandle",
             "type": "string",
             "description": "An opaque identifier for a browsing context."
@@ -446,11 +456,11 @@
                 { "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." }
+                { "name": "coordinateSystem", "$ref": "CoordinateSystem", "description": "The coordinate system to use for rect and point results." }
             ],
             "returns": [
-                { "name": "rect", "$ref": "Rect", "description": "The layout rect for the requested element. Specified in page or viewport coordinates based on the useViewportCoordinates parameter." },
-                { "name": "inViewCenterPoint", "optional": true, "$ref": "Point", "description": "The in-view center point for the requested element. Specified in page or viewport coordinates based on the useViewportCoordinates parameter." },
+                { "name": "rect", "$ref": "Rect", "description": "The layout rect for the requested element. Values are converted to the requested coordinate system." },
+                { "name": "inViewCenterPoint", "optional": true, "$ref": "Point", "description": "The in-view center point for the requested element. Values are converted to the requested coordinate system." },
                 { "name": "isObscured", "type": "boolean", "description": "If the in-view center point of the requested element is obscured by another element." }
             ],
             "async": true

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (224788 => 224789)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2017-11-13 23:21:31 UTC (rev 224789)
@@ -30,6 +30,7 @@
 #include "APIAutomationSessionClient.h"
 #include "APIOpenPanelParameters.h"
 #include "AutomationProtocolObjects.h"
+#include "CoordinateSystem.h"
 #include "WebAutomationSessionMacros.h"
 #include "WebAutomationSessionMessages.h"
 #include "WebAutomationSessionProxyMessages.h"
@@ -873,8 +874,19 @@
         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)
+static std::optional<CoordinateSystem> protocolStringToCoordinateSystem(const String& coordinateSystemString)
 {
+    if (coordinateSystemString == "Page")
+        return CoordinateSystem::Page;
+    if (coordinateSystemString == "LayoutViewport")
+        return CoordinateSystem::LayoutViewport;
+    if (coordinateSystemString == "VisualViewport")
+        return CoordinateSystem::VisualViewport;
+    return std::nullopt;
+}
+
+void WebAutomationSession::computeElementLayout(Inspector::ErrorString& errorString, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const String& coordinateSystemString, Ref<ComputeElementLayoutCallback>&& callback)
+{
     WebPageProxy* page = webPageProxyForHandle(browsingContextHandle);
     if (!page)
         FAIL_WITH_PREDEFINED_ERROR(WindowNotFound);
@@ -883,13 +895,15 @@
     if (!frameID)
         FAIL_WITH_PREDEFINED_ERROR(FrameNotFound);
 
+    std::optional<CoordinateSystem> coordinateSystem = protocolStringToCoordinateSystem(coordinateSystemString);
+    if (!coordinateSystem)
+        FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "The parameter 'coordinateSystem' is invalid.");
+
     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(page->pageID(), frameID.value(), nodeHandle, scrollIntoViewIfNeeded, useViewportCoordinates, callbackID), 0);
+    page->process().send(Messages::WebAutomationSessionProxy::ComputeElementLayout(page->pageID(), frameID.value(), nodeHandle, scrollIntoViewIfNeeded, coordinateSystem.value(), callbackID), 0);
 }
 
 void WebAutomationSession::didComputeElementLayout(uint64_t callbackID, WebCore::IntRect rect, std::optional<WebCore::IntPoint> inViewCenterPoint, bool isObscured, const String& errorType)

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h (224788 => 224789)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h	2017-11-13 23:21:31 UTC (rev 224789)
@@ -135,7 +135,7 @@
     void takeScreenshot(Inspector::ErrorString&, const String& handle, const String* optionalFrameHandle, const String* optionalNodeHandle, const bool* optionalScrollIntoViewIfNeeded, Ref<TakeScreenshotCallback>&&) 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;
+    void computeElementLayout(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, const bool* optionalScrollIntoViewIfNeeded, const String& coordinateSystem, Ref<Inspector::AutomationBackendDispatcherHandler::ComputeElementLayoutCallback>&&) override;
     void selectOptionElement(Inspector::ErrorString&, const String& browsingContextHandle, const String& frameHandle, const String& nodeHandle, Ref<Inspector::AutomationBackendDispatcherHandler::SelectOptionElementCallback>&&) override;
     void isShowingJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle, bool* result) override;
     void dismissCurrentJavaScriptDialog(Inspector::ErrorString&, const String& browsingContextHandle) override;

Modified: trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj (224788 => 224789)


--- trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj	2017-11-13 23:21:31 UTC (rev 224789)
@@ -3897,6 +3897,7 @@
 		99C81D561C20DFBE005C4C82 /* AutomationClient.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AutomationClient.mm; sourceTree = "<group>"; };
 		99C81D5B1C20E817005C4C82 /* APIAutomationClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = APIAutomationClient.h; sourceTree = "<group>"; };
 		99E714C11C1249E600665B3A /* _WKAutomationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _WKAutomationDelegate.h; sourceTree = "<group>"; };
+		99F642D21FABE378009621E9 /* CoordinateSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoordinateSystem.h; sourceTree = "<group>"; };
 		9BC59D6C1EFCCCB6001E8D09 /* CallbackID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CallbackID.h; sourceTree = "<group>"; };
 		9BC59D6D1EFCDC6D001E8D09 /* OptionalCallbackID.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OptionalCallbackID.h; sourceTree = "<group>"; };
 		9F54F88E16488E87007DF81A /* ChildProcessMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ChildProcessMac.mm; sourceTree = "<group>"; };
@@ -5058,6 +5059,7 @@
 				290F4271172A0C7400939FF0 /* ChildProcessSupplement.h */,
 				5106D7BF18BDBE73000AB166 /* ContextMenuContextData.cpp */,
 				5106D7C018BDBE73000AB166 /* ContextMenuContextData.h */,
+				99F642D21FABE378009621E9 /* CoordinateSystem.h */,
 				C517388012DF8F4F00EE3F47 /* DragControllerAction.h */,
 				0FB659221208B4DB0044816C /* DrawingAreaInfo.h */,
 				E105FE5318D7B9DE008F57A8 /* EditingRange.h */,

Modified: trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp (224788 => 224789)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2017-11-13 23:21:31 UTC (rev 224789)
@@ -27,6 +27,7 @@
 #include "WebAutomationSessionProxy.h"
 
 #include "AutomationProtocolObjects.h"
+#include "CoordinateSystem.h"
 #include "WebAutomationSessionMessages.h"
 #include "WebAutomationSessionProxyMessages.h"
 #include "WebAutomationSessionProxyScriptSource.h"
@@ -533,7 +534,7 @@
     return &element;
 }
 
-void WebAutomationSessionProxy::computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
+void WebAutomationSessionProxy::computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, CoordinateSystem coordinateSystem, uint64_t callbackID)
 {
     WebPage* page = WebProcess::singleton().webPage(pageID);
     if (!page) {
@@ -544,6 +545,7 @@
 
     String frameNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::FrameNotFound);
     String nodeNotFoundErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::NodeNotFound);
+    String notImplementedErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::NotImplemented);
 
     WebFrame* frame = frameID ? WebProcess::singleton().webFrame(frameID) : page->mainWebFrame();
     if (!frame || !frame->coreFrame() || !frame->coreFrame()->view()) {
@@ -565,25 +567,46 @@
         // FIXME: Wait in an implementation-specific way up to the session implicit wait timeout for the element to become in view.
     }
 
-    WebCore::IntRect rect = coreElement->clientRect();
+    if (coordinateSystem == CoordinateSystem::VisualViewport) {
+        WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, { }, std::nullopt, false, notImplementedErrorType), 0);
+        return;
+    }
 
+    WebCore::FloatRect elementBounds = coreElement->boundingClientRect();
+
     auto* coreFrameView = frame->coreFrame()->view();
-    if (useViewportCoordinates)
-        rect.moveBy(WebCore::IntPoint(0, -coreFrameView->topContentInset()));
-    else
-        rect = coreFrameView->rootViewToContents(rect);
+    switch (coordinateSystem) {
+    case CoordinateSystem::Page:
+        elementBounds = coreFrameView->clientToDocumentRect(elementBounds);
+        break;
+    case CoordinateSystem::LayoutViewport:
+        // The element bounds are already in client coordinates.
+        break;
+    case CoordinateSystem::VisualViewport:
+        ASSERT_NOT_REACHED();
+        break;
+    }
 
+    std::optional<WebCore::FloatPoint> inViewCenterPoint;
     bool isObscured = false;
-    std::optional<WebCore::IntPoint> inViewCenter;
     if (containerElement) {
-        if (auto clientCenterPoint = elementInViewClientCenterPoint(*containerElement, isObscured)) {
-            inViewCenter = WebCore::IntPoint(coreFrameView->clientToDocumentPoint(clientCenterPoint.value()));
-            if (useViewportCoordinates)
-                inViewCenter = coreFrameView->contentsToRootView(inViewCenter.value());
+        inViewCenterPoint = elementInViewClientCenterPoint(*containerElement, isObscured);
+        if (inViewCenterPoint.has_value()) {
+            switch (coordinateSystem) {
+            case CoordinateSystem::Page:
+                inViewCenterPoint = coreFrameView->clientToDocumentPoint(inViewCenterPoint.value());
+                break;
+            case CoordinateSystem::LayoutViewport:
+                // The point is already in client coordinates.
+                break;
+            case CoordinateSystem::VisualViewport:
+                ASSERT_NOT_REACHED();
+                break;
+            }
         }
     }
 
-    WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, rect, inViewCenter, isObscured, String()), 0);
+    WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidComputeElementLayout(callbackID, enclosingIntRect(elementBounds), WebCore::IntPoint(inViewCenterPoint.value()), isObscured, String()), 0);
 }
 
 void WebAutomationSessionProxy::selectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID)

Modified: trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h (224788 => 224789)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.h	2017-11-13 23:21:31 UTC (rev 224789)
@@ -23,10 +23,10 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef WebAutomationSessionProxy_h
-#define WebAutomationSessionProxy_h
+#pragma once
 
 #include "Connection.h"
+#include "CoordinateSystem.h"
 #include <_javascript_Core/JSBase.h>
 #include <wtf/text/WTFString.h>
 
@@ -64,7 +64,7 @@
     void resolveChildFrameWithName(uint64_t pageID, uint64_t frameID, const String& name, uint64_t callbackID);
     void resolveParentFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID);
     void focusFrame(uint64_t pageID, uint64_t frameID);
-    void computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID);
+    void computeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, CoordinateSystem, uint64_t callbackID);
     void selectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID);
     void takeScreenshot(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, uint64_t callbackID);
     void getCookiesForFrame(uint64_t pageID, uint64_t frameID, uint64_t callbackID);
@@ -77,5 +77,3 @@
 };
 
 } // namespace WebKit
-
-#endif // WebAutomationSessionProxy_h

Modified: trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.messages.in (224788 => 224789)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.messages.in	2017-11-13 23:15:57 UTC (rev 224788)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.messages.in	2017-11-13 23:21:31 UTC (rev 224789)
@@ -30,7 +30,7 @@
 
     FocusFrame(uint64_t pageID, uint64_t frameID)
 
-    ComputeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, bool useViewportCoordinates, uint64_t callbackID)
+ComputeElementLayout(uint64_t pageID, uint64_t frameID, String nodeHandle, bool scrollIntoViewIfNeeded, enum WebKit::CoordinateSystem coordinateSystem, uint64_t callbackID)
 
     SelectOptionElement(uint64_t pageID, uint64_t frameID, String nodeHandle, uint64_t callbackID)
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to