Title: [230088] trunk/Source/WebKit
Revision
230088
Author
bb...@apple.com
Date
2018-03-29 17:07:40 -0700 (Thu, 29 Mar 2018)

Log Message

Web Automation: clipToViewport is ignored for element screenshots
https://bugs.webkit.org/show_bug.cgi?id=184158
<rdar://problem/39014307>

Reviewed by Timothy Hatcher.

In §19.2 Take Element Screenshot, step 5.2 says that we should clip
the element screenshot rect with the visible viewport rect. We don't
do that right now even though we pass over clipToViewport.

* WebProcess/Automation/WebAutomationSessionProxy.cpp:
(WebKit::snapshotRectForScreenshot):
Clip the rect to viewport if needed.

(WebKit::WebAutomationSessionProxy::takeScreenshot):
This scrollIntoView is misplaced; by this point we have already done
the math to figure out the screenshot rect. Move it before computing the rect.

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (230087 => 230088)


--- trunk/Source/WebKit/ChangeLog	2018-03-29 23:05:06 UTC (rev 230087)
+++ trunk/Source/WebKit/ChangeLog	2018-03-30 00:07:40 UTC (rev 230088)
@@ -1,3 +1,23 @@
+2018-03-29  Brian Burg  <bb...@apple.com>
+
+        Web Automation: clipToViewport is ignored for element screenshots
+        https://bugs.webkit.org/show_bug.cgi?id=184158
+        <rdar://problem/39014307>
+
+        Reviewed by Timothy Hatcher.
+
+        In §19.2 Take Element Screenshot, step 5.2 says that we should clip
+        the element screenshot rect with the visible viewport rect. We don't
+        do that right now even though we pass over clipToViewport.
+
+        * WebProcess/Automation/WebAutomationSessionProxy.cpp:
+        (WebKit::snapshotRectForScreenshot):
+        Clip the rect to viewport if needed.
+
+        (WebKit::WebAutomationSessionProxy::takeScreenshot):
+        This scrollIntoView is misplaced; by this point we have already done
+        the math to figure out the screenshot rect. Move it before computing the rect.
+
 2018-03-29  Brent Fulgham  <bfulg...@apple.com>
 
         REGRESSION(r230035): ASSERT(MACH_PORT_VALID(m_sendPort)) hit in IPC::Connection::initializeSendSource()

Modified: trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp (230087 => 230088)


--- trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2018-03-29 23:05:06 UTC (rev 230087)
+++ trunk/Source/WebKit/WebProcess/Automation/WebAutomationSessionProxy.cpp	2018-03-30 00:07:40 UTC (rev 230088)
@@ -663,12 +663,20 @@
 
 static WebCore::IntRect snapshotRectForScreenshot(WebPage& page, WebCore::Element* element, bool clipToViewport)
 {
+    auto* frameView = page.mainFrameView();
+    if (!frameView)
+        return { };
+
     if (element) {
         if (!element->renderer())
             return { };
 
         WebCore::LayoutRect topLevelRect;
-        return WebCore::snappedIntRect(element->renderer()->paintingRootRect(topLevelRect));
+        WebCore::IntRect elementRect = WebCore::snappedIntRect(element->renderer()->paintingRootRect(topLevelRect));
+        if (clipToViewport)
+            elementRect.intersect(frameView->visibleContentRect());
+
+        return elementRect;
     }
 
     if (auto* frameView = page.mainFrameView())
@@ -705,6 +713,9 @@
         }
     }
 
+    if (coreElement && scrollIntoViewIfNeeded)
+        coreElement->scrollIntoViewIfNeeded(false);
+
     String screenshotErrorType = Inspector::Protocol::AutomationHelpers::getEnumConstantValue(Inspector::Protocol::Automation::ErrorMessage::ScreenshotError);
     WebCore::IntRect snapshotRect = snapshotRectForScreenshot(*page, coreElement, clipToViewport);
     if (snapshotRect.isEmpty()) {
@@ -712,9 +723,6 @@
         return;
     }
 
-    if (coreElement && scrollIntoViewIfNeeded)
-        coreElement->scrollIntoViewIfNeeded(false);
-
     RefPtr<WebImage> image = page->scaledSnapshotWithOptions(snapshotRect, 1, SnapshotOptionsShareable);
     if (!image) {
         WebProcess::singleton().parentProcessConnection()->send(Messages::WebAutomationSession::DidTakeScreenshot(callbackID, handle, screenshotErrorType), 0);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to