Title: [291519] trunk/Source/WebCore
Revision
291519
Author
pan...@apple.com
Date
2022-03-18 20:25:35 -0700 (Fri, 18 Mar 2022)

Log Message

Web Inspector: `console.screenshot` has extra transparent pixels at bottom of screenshot on platforms with viewports that are obscured by browser chrome
https://bugs.webkit.org/show_bug.cgi?id=238060

Reviewed by Devin Rousso.

ScrollView::sizeForVisibleRect includes partially-visible portions of the viewport, including in Safari's case
the part of the viewport under the semi-translucent title bar. Because we force an origin of zero, this meant
that we were overshooting the bottom of the viewport by the height of this area when taking a snapshot for
`console.screenshot()`. Instead, we should use unobscured viewport rectangle and provide coordinates in
document-space, not view-space to `WebCore::snapshotFrameRect`.

* page/PageConsoleClient.cpp:
(WebCore::PageConsoleClient::screenshot):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (291518 => 291519)


--- trunk/Source/WebCore/ChangeLog	2022-03-19 02:00:37 UTC (rev 291518)
+++ trunk/Source/WebCore/ChangeLog	2022-03-19 03:25:35 UTC (rev 291519)
@@ -1,3 +1,19 @@
+2022-03-18  Patrick Angle  <pan...@apple.com>
+
+        Web Inspector: `console.screenshot` has extra transparent pixels at bottom of screenshot on platforms with viewports that are obscured by browser chrome
+        https://bugs.webkit.org/show_bug.cgi?id=238060
+
+        Reviewed by Devin Rousso.
+
+        ScrollView::sizeForVisibleRect includes partially-visible portions of the viewport, including in Safari's case
+        the part of the viewport under the semi-translucent title bar. Because we force an origin of zero, this meant
+        that we were overshooting the bottom of the viewport by the height of this area when taking a snapshot for
+        `console.screenshot()`. Instead, we should use unobscured viewport rectangle and provide coordinates in
+        document-space, not view-space to `WebCore::snapshotFrameRect`.
+
+        * page/PageConsoleClient.cpp:
+        (WebCore::PageConsoleClient::screenshot):
+
 2022-03-18  Devin Rousso  <drou...@apple.com>
 
         Web Inspector: REGRESSION(?): Emulate User Gesture doesn't work

Modified: trunk/Source/WebCore/page/PageConsoleClient.cpp (291518 => 291519)


--- trunk/Source/WebCore/page/PageConsoleClient.cpp	2022-03-19 02:00:37 UTC (rev 291518)
+++ trunk/Source/WebCore/page/PageConsoleClient.cpp	2022-03-19 03:25:35 UTC (rev 291519)
@@ -411,8 +411,8 @@
     if (UNLIKELY(InspectorInstrumentation::hasFrontends())) {
         if (!target) {
             // If no target is provided, capture an image of the viewport.
-            IntRect imageRect(IntPoint::zero(), m_page.mainFrame().view()->sizeForVisibleContent());
-            if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), imageRect, { { SnapshotFlags::InViewCoordinates }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }))
+            auto viewportRect = m_page.mainFrame().view()->unobscuredContentRect();
+            if (auto snapshot = WebCore::snapshotFrameRect(m_page.mainFrame(), viewportRect, { { }, PixelFormat::BGRA8, DestinationColorSpace::SRGB() }))
                 dataURL = snapshot->toDataURL("image/png"_s, std::nullopt, PreserveResolution::Yes);
         }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to