Title: [271691] trunk
Revision
271691
Author
akeer...@apple.com
Date
2021-01-21 07:47:16 -0800 (Thu, 21 Jan 2021)

Log Message

[macOS] Titlebar separator doesn't show when WKWebView is scrolled
https://bugs.webkit.org/show_bug.cgi?id=220633
<rdar://problem/71094055>

Reviewed by Tim Horton.

Source/WebKit:

Starting in Big Sur, NSWindows with a titlebar display a separator if
there is a scrolled NSScrollView adjacent to the titlebar. Since
WKWebViews are scrollable views, but not backed by NSScrollView, we
need to adopt SPI to support this functionality.

This patch updates WKWebView to conform to the NSScrollViewSeparatorTrackingAdapter
protocol, ensuring the titlebar separator is displayed when
necessary. Note that since WKWebViews are not actually NSScrollView's we
don't already have the scroll position of the view in the UIProcess. To
determine whether or not the view is scrolled, this patch adds plumbing
so that the WebProcess can tell the UIProcess the new scroll position
when a page is scrolled.

Tests: WKWebViewTitlebarSeparatorTests.BackForwardCache
       WKWebViewTitlebarSeparatorTests.ChangeTitlebarAdjacency
       WKWebViewTitlebarSeparatorTests.ChangeViewVisibility
       WKWebViewTitlebarSeparatorTests.NavigationResetsTitlebarAppearance
       WKWebViewTitlebarSeparatorTests.ScrollWithTitlebarAdjacency
       WKWebViewTitlebarSeparatorTests.ScrollWithoutTitlebarAdjacency

* Platform/spi/mac/AppKitSPI.h:
* UIProcess/API/mac/WKView.mm:
(-[WKView scrollViewFrame]):
(-[WKView hasScrolledContentsUnderTitlebar]):
(-[WKView _web_registerScrollViewSeparatorTrackingAdapter]):
(-[WKView _web_unregisterScrollViewSeparatorTrackingAdapter]):
* UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView scrollViewFrame]):
(-[WKWebView hasScrolledContentsUnderTitlebar]):
(-[WKWebView _web_registerScrollViewSeparatorTrackingAdapter]):
(-[WKWebView _web_unregisterScrollViewSeparatorTrackingAdapter]):
* UIProcess/Cocoa/WebViewImpl.h:
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::updateWindowAndViewFrames):

If the WKWebView's frame changes, update the titlebar adjacency
state and notify observers of the change.

(WebKit::WebViewImpl::viewWillMoveToWindowImpl):

Unregister the WKWebView as an NSScrollViewSeparatorTrackingAdapter if
it is removed from the window.

(WebKit::WebViewImpl::viewDidHide):

Hidden views are not adjacent to the titlebar.

(WebKit::WebViewImpl::viewDidUnhide):

An unhidden view may be adjacent to the titlebar.

(WebKit::WebViewImpl::pageDidScroll):

Use the scroll position of the page to determine whether or not the
WKWebView is scrolled.

(WebKit::WebViewImpl::scrollViewFrame):

Needed to conform to NSScrollViewSeparatorTrackingAdapter.

(WebKit::WebViewImpl::hasScrolledContentsUnderTitlebar):

Needed to conform to NSScrollViewSeparatorTrackingAdapter. Returns true
if the view is registered as an NSScrollViewSeparatorTrackingAdapter
and is scrolled.

(WebKit::WebViewImpl::updateTitlebarAdjacencyState):

The WKWebView needs to be registered as an NSScrollViewSeparatorTrackingAdapter
if it's adjacent to the titlebar and unregistered otherwise.

* UIProcess/PageClient.h:
(WebKit::PageClient::pageDidScroll):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::pageDidScroll):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/PageClientImplMac.h:
* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::didCommitLoadForMainFrame):

Reset the scroll position upon navigation, as pageDidScroll does not get
called when navigating.

(WebKit::PageClientImpl::pageDidScroll):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::pageDidScroll):

Pass the current scroll position when the page is scrolled, so that the
UIProcess knows whether or not the page has a non-zero scroll position.

Source/WTF:

* wtf/PlatformHave.h: Defined HAVE_NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER.

Tools:

Added API tests to verify that the delegate implementation returns the
correct value for `hasScrolledContentsUnderTitlebar` depending on
the view's scroll position, visibility, and frame.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h:
* TestWebKitAPI/Tests/mac/WKWebViewTitlebarSeparatorTests.mm: Added.
(-[TitlebarSeparatorTestWKWebView initWithFrame:configuration:]):
(-[TitlebarSeparatorTestWKWebView separatorTrackingAdapter]):
(BackForwardCache):
(ChangeTitlebarAdjacency):
(ChangeViewVisibility):
(NavigationResetsTitlebarAppearance):
(ScrollWithTitlebarAdjacency):
(ScrollWithoutTitlebarAdjacency):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (271690 => 271691)


--- trunk/Source/WTF/ChangeLog	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WTF/ChangeLog	2021-01-21 15:47:16 UTC (rev 271691)
@@ -1,3 +1,13 @@
+2021-01-21  Aditya Keerthi  <akeer...@apple.com>
+
+        [macOS] Titlebar separator doesn't show when WKWebView is scrolled
+        https://bugs.webkit.org/show_bug.cgi?id=220633
+        <rdar://problem/71094055>
+
+        Reviewed by Tim Horton.
+
+        * wtf/PlatformHave.h: Defined HAVE_NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER.
+
 2021-01-20  Youenn Fablet  <you...@apple.com>
 
         Enable WebRTC VP9 profile 0 by default

Modified: trunk/Source/WTF/wtf/PlatformHave.h (271690 => 271691)


--- trunk/Source/WTF/wtf/PlatformHave.h	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WTF/wtf/PlatformHave.h	2021-01-21 15:47:16 UTC (rev 271691)
@@ -826,3 +826,7 @@
     || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 140400)
 #define HAVE_AVCONTENTKEYREQUEST_PENDING_PROTECTION_STATUS 1
 #endif
+
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000
+#define HAVE_NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER 1
+#endif

Modified: trunk/Source/WebKit/ChangeLog (271690 => 271691)


--- trunk/Source/WebKit/ChangeLog	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/ChangeLog	2021-01-21 15:47:16 UTC (rev 271691)
@@ -1,3 +1,102 @@
+2021-01-21  Aditya Keerthi  <akeer...@apple.com>
+
+        [macOS] Titlebar separator doesn't show when WKWebView is scrolled
+        https://bugs.webkit.org/show_bug.cgi?id=220633
+        <rdar://problem/71094055>
+
+        Reviewed by Tim Horton.
+
+        Starting in Big Sur, NSWindows with a titlebar display a separator if
+        there is a scrolled NSScrollView adjacent to the titlebar. Since
+        WKWebViews are scrollable views, but not backed by NSScrollView, we
+        need to adopt SPI to support this functionality.
+
+        This patch updates WKWebView to conform to the NSScrollViewSeparatorTrackingAdapter
+        protocol, ensuring the titlebar separator is displayed when
+        necessary. Note that since WKWebViews are not actually NSScrollView's we
+        don't already have the scroll position of the view in the UIProcess. To
+        determine whether or not the view is scrolled, this patch adds plumbing
+        so that the WebProcess can tell the UIProcess the new scroll position
+        when a page is scrolled.
+
+        Tests: WKWebViewTitlebarSeparatorTests.BackForwardCache
+               WKWebViewTitlebarSeparatorTests.ChangeTitlebarAdjacency
+               WKWebViewTitlebarSeparatorTests.ChangeViewVisibility
+               WKWebViewTitlebarSeparatorTests.NavigationResetsTitlebarAppearance
+               WKWebViewTitlebarSeparatorTests.ScrollWithTitlebarAdjacency
+               WKWebViewTitlebarSeparatorTests.ScrollWithoutTitlebarAdjacency
+
+        * Platform/spi/mac/AppKitSPI.h:
+        * UIProcess/API/mac/WKView.mm:
+        (-[WKView scrollViewFrame]):
+        (-[WKView hasScrolledContentsUnderTitlebar]):
+        (-[WKView _web_registerScrollViewSeparatorTrackingAdapter]):
+        (-[WKView _web_unregisterScrollViewSeparatorTrackingAdapter]):
+        * UIProcess/API/mac/WKWebViewMac.mm:
+        (-[WKWebView scrollViewFrame]):
+        (-[WKWebView hasScrolledContentsUnderTitlebar]):
+        (-[WKWebView _web_registerScrollViewSeparatorTrackingAdapter]):
+        (-[WKWebView _web_unregisterScrollViewSeparatorTrackingAdapter]):
+        * UIProcess/Cocoa/WebViewImpl.h:
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::updateWindowAndViewFrames):
+
+        If the WKWebView's frame changes, update the titlebar adjacency
+        state and notify observers of the change.
+
+        (WebKit::WebViewImpl::viewWillMoveToWindowImpl):
+
+        Unregister the WKWebView as an NSScrollViewSeparatorTrackingAdapter if
+        it is removed from the window.
+
+        (WebKit::WebViewImpl::viewDidHide):
+
+        Hidden views are not adjacent to the titlebar.
+
+        (WebKit::WebViewImpl::viewDidUnhide):
+
+        An unhidden view may be adjacent to the titlebar.
+
+        (WebKit::WebViewImpl::pageDidScroll):
+
+        Use the scroll position of the page to determine whether or not the
+        WKWebView is scrolled.
+
+        (WebKit::WebViewImpl::scrollViewFrame):
+
+        Needed to conform to NSScrollViewSeparatorTrackingAdapter.
+
+        (WebKit::WebViewImpl::hasScrolledContentsUnderTitlebar):
+
+        Needed to conform to NSScrollViewSeparatorTrackingAdapter. Returns true
+        if the view is registered as an NSScrollViewSeparatorTrackingAdapter
+        and is scrolled.
+
+        (WebKit::WebViewImpl::updateTitlebarAdjacencyState):
+
+        The WKWebView needs to be registered as an NSScrollViewSeparatorTrackingAdapter
+        if it's adjacent to the titlebar and unregistered otherwise.
+
+        * UIProcess/PageClient.h:
+        (WebKit::PageClient::pageDidScroll):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::pageDidScroll):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/mac/PageClientImplMac.h:
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::didCommitLoadForMainFrame):
+
+        Reset the scroll position upon navigation, as pageDidScroll does not get
+        called when navigating.
+
+        (WebKit::PageClientImpl::pageDidScroll):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::pageDidScroll):
+
+        Pass the current scroll position when the page is scrolled, so that the
+        UIProcess knows whether or not the page has a non-zero scroll position.
+
 2021-01-21  Dave Blanchard  <d...@grow.game>
 
         Missing header gtk/gtk.h in PointerLockManagerX11.cpp

Modified: trunk/Source/WebKit/Platform/spi/mac/AppKitSPI.h (271690 => 271691)


--- trunk/Source/WebKit/Platform/spi/mac/AppKitSPI.h	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/Platform/spi/mac/AppKitSPI.h	2021-01-21 15:47:16 UTC (rev 271691)
@@ -31,6 +31,10 @@
 #import <AppKit/NSTextInputClient_Private.h>
 #import <AppKit/NSWindow_Private.h>
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+#import <AppKit/NSScrollViewSeparatorTrackingAdapter_Private.h>
+#endif
+
 #else
 
 @interface NSInspectorBar : NSObject
@@ -37,6 +41,13 @@
 @property (getter=isVisible) BOOL visible;
 @end
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+@protocol NSScrollViewSeparatorTrackingAdapter
+@property (readonly) NSRect scrollViewFrame;
+@property (readonly) BOOL hasScrolledContentsUnderTitlebar;
+@end
+#endif
+
 @protocol NSTextInputClient_Async
 @end
 
@@ -54,6 +65,11 @@
 @property CGFloat titlebarAlphaValue;
 #endif
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+- (BOOL)registerScrollViewSeparatorTrackingAdapter:(NSObject<NSScrollViewSeparatorTrackingAdapter> *)adapter;
+- (void)unregisterScrollViewSeparatorTrackingAdapter:(NSObject<NSScrollViewSeparatorTrackingAdapter> *)adapter;
+#endif
+
 @end
 
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKView.mm (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2021-01-21 15:47:16 UTC (rev 271691)
@@ -31,6 +31,7 @@
 #import "APIHitTestResult.h"
 #import "APIIconLoadingClient.h"
 #import "APIPageConfiguration.h"
+#import "AppKitSPI.h"
 #import "WKBrowsingContextGroupPrivate.h"
 #import "WKNSData.h"
 #import "WKProcessGroupPrivate.h"
@@ -67,6 +68,11 @@
 @end
 #endif
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+@interface WKView() <NSScrollViewSeparatorTrackingAdapter>
+@end
+#endif
+
 #if ENABLE(DRAG_SUPPORT)
 
 @interface WKView () <NSFilePromiseProviderDelegate, NSDraggingSource>
@@ -1127,6 +1133,34 @@
 
 #endif // HAVE(TOUCH_BAR)
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
+- (NSRect)scrollViewFrame
+{
+    if (!_data->_impl)
+        return NSZeroRect;
+    return _data->_impl->scrollViewFrame();
+}
+
+- (BOOL)hasScrolledContentsUnderTitlebar
+{
+    if (!_data->_impl)
+        return NO;
+    return _data->_impl->hasScrolledContentsUnderTitlebar();
+}
+
+- (BOOL)_web_registerScrollViewSeparatorTrackingAdapter
+{
+    return [self.window registerScrollViewSeparatorTrackingAdapter:self];
+}
+
+- (void)_web_unregisterScrollViewSeparatorTrackingAdapter
+{
+    [self.window unregisterScrollViewSeparatorTrackingAdapter:self];
+}
+
+#endif // HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
 #if ENABLE(DRAG_SUPPORT)
 
 - (NSString *)filePromiseProvider:(NSFilePromiseProvider *)filePromiseProvider fileNameForType:(NSString *)fileType

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2021-01-21 15:47:16 UTC (rev 271691)
@@ -84,6 +84,9 @@
     , NSFilePromiseProviderDelegate
     , NSDraggingSource
 #endif
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    , NSScrollViewSeparatorTrackingAdapter
+#endif
     >
 @end
 
@@ -994,6 +997,36 @@
 
 #endif // HAVE(TOUCH_BAR)
 
+#pragma mark - NSScrollViewSeparatorTrackingAdapter
+
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
+- (NSRect)scrollViewFrame
+{
+    if (!_impl)
+        return NSZeroRect;
+    return _impl->scrollViewFrame();
+}
+
+- (BOOL)hasScrolledContentsUnderTitlebar
+{
+    if (!_impl)
+        return NO;
+    return _impl->hasScrolledContentsUnderTitlebar();
+}
+
+- (BOOL)_web_registerScrollViewSeparatorTrackingAdapter
+{
+    return [self.window registerScrollViewSeparatorTrackingAdapter:self];
+}
+
+- (void)_web_unregisterScrollViewSeparatorTrackingAdapter
+{
+    [self.window unregisterScrollViewSeparatorTrackingAdapter:self];
+}
+
+#endif // HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
 @end
 
 #pragma mark -

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2021-01-21 15:47:16 UTC (rev 271691)
@@ -88,6 +88,7 @@
 }
 
 namespace WebCore {
+class IntPoint;
 struct ShareDataWithParsedURL;
 }
 
@@ -131,6 +132,11 @@
 - (void)_didHandleAcceptedCandidate;
 - (void)_didUpdateCandidateListVisibility:(BOOL)visible;
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+- (BOOL)_web_registerScrollViewSeparatorTrackingAdapter;
+- (void)_web_unregisterScrollViewSeparatorTrackingAdapter;
+#endif
+
 @end
 
 namespace WebCore {
@@ -287,6 +293,14 @@
     void viewDidUnhide();
     void activeSpaceDidChange();
 
+    void pageDidScroll(const WebCore::IntPoint&);
+
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    NSRect scrollViewFrame();
+    bool hasScrolledContentsUnderTitlebar();
+    void updateTitlebarAdjacencyState();
+#endif
+
     NSView *hitTest(CGPoint);
 
     ColorSpaceData colorSpace();
@@ -828,6 +842,11 @@
     NSInteger m_initialNumberOfValidItemsForDrop { 0 };
 #endif
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    bool m_pageIsScrolled { false };
+    bool m_isRegisteredScrollViewSeparatorTrackingAdapter { false };
+#endif
+
     RetainPtr<NSMenu> m_domPasteMenu;
     RetainPtr<WKDOMPasteMenuDelegate> m_domPasteMenuDelegate;
     CompletionHandler<void(WebCore::DOMPasteAccessResponse)> m_domPasteRequestHandler;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2021-01-21 15:47:16 UTC (rev 271691)
@@ -115,6 +115,7 @@
 #import <pal/spi/cocoa/NSTouchBarSPI.h>
 #import <pal/spi/mac/DataDetectorsSPI.h>
 #import <pal/spi/mac/LookupSPI.h>
+#import <pal/spi/mac/NSAppearanceSPI.h>
 #import <pal/spi/mac/NSApplicationSPI.h>
 #import <pal/spi/mac/NSImmediateActionGestureRecognizerSPI.h>
 #import <pal/spi/mac/NSScrollerImpSPI.h>
@@ -1804,6 +1805,11 @@
     if (clipsToVisibleRect())
         updateViewExposedRect();
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    [m_view didChangeValueForKey:@"scrollViewFrame"];
+    updateTitlebarAdjacencyState();
+#endif
+
     if (m_didScheduleWindowAndViewFrameUpdate)
         return;
 
@@ -2303,6 +2309,15 @@
     NSWindow *stopObservingWindow = m_targetWindowForMovePreparation ? m_targetWindowForMovePreparation.get() : [m_view window];
     [m_windowVisibilityObserver stopObserving:stopObservingWindow];
     [m_windowVisibilityObserver startObserving:window];
+
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    if (m_isRegisteredScrollViewSeparatorTrackingAdapter) {
+        if ([m_view respondsToSelector:@selector(_web_unregisterScrollViewSeparatorTrackingAdapter)]) {
+            [m_view _web_unregisterScrollViewSeparatorTrackingAdapter];
+            m_isRegisteredScrollViewSeparatorTrackingAdapter = false;
+        }
+    }
+#endif
 }
 
 void WebViewImpl::viewWillMoveToWindow(NSWindow *window)
@@ -2384,6 +2399,9 @@
 {
     LOG(ActivityState, "WebViewImpl %p (page %llu) viewDidHide", this, m_page->identifier().toUInt64());
     m_page->activityStateDidChange(WebCore::ActivityState::IsVisible);
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    updateTitlebarAdjacencyState();
+#endif
 }
 
 void WebViewImpl::viewDidUnhide()
@@ -2390,6 +2408,9 @@
 {
     LOG(ActivityState, "WebViewImpl %p (page %llu) viewDidUnhide", this, m_page->identifier().toUInt64());
     m_page->activityStateDidChange(WebCore::ActivityState::IsVisible);
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    updateTitlebarAdjacencyState();
+#endif
 }
 
 void WebViewImpl::activeSpaceDidChange()
@@ -2398,6 +2419,57 @@
     m_page->activityStateDidChange(WebCore::ActivityState::IsVisible);
 }
 
+void WebViewImpl::pageDidScroll(const WebCore::IntPoint& scrollPosition)
+{
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+    if (!m_isRegisteredScrollViewSeparatorTrackingAdapter)
+        return;
+
+    if ((scrollPosition.y() > 0 && !m_pageIsScrolled) || (scrollPosition.y() <= 0 && m_pageIsScrolled)) {
+        [m_view willChangeValueForKey:@"hasScrolledContentsUnderTitlebar"];
+        m_pageIsScrolled = !m_pageIsScrolled;
+        [m_view didChangeValueForKey:@"hasScrolledContentsUnderTitlebar"];
+    }
+#endif
+}
+
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
+NSRect WebViewImpl::scrollViewFrame()
+{
+    return [m_view convertRect:[m_view bounds] toView:nil];
+}
+
+bool WebViewImpl::hasScrolledContentsUnderTitlebar()
+{
+    return m_isRegisteredScrollViewSeparatorTrackingAdapter && m_pageIsScrolled;
+}
+
+void WebViewImpl::updateTitlebarAdjacencyState()
+{
+    BOOL wantsScrollViewSeparatorTrackingAdapterRegistration = false;
+
+    NSWindow *window = [m_view window];
+    BOOL visible = ![m_view isHiddenOrHasHiddenAncestor];
+    NSRect windowContentLayoutRectInSelf = [m_view convertRect:[window contentLayoutRect] fromView:nil];
+    BOOL topOfWindowContentLayoutRectAdjacent = (NSMinY([m_view bounds]) <= NSMinY(windowContentLayoutRectInSelf));
+
+    if (topOfWindowContentLayoutRectAdjacent && visible && [[m_view effectiveAppearance] _usesMetricsAppearance])
+        wantsScrollViewSeparatorTrackingAdapterRegistration = YES;
+
+    if (wantsScrollViewSeparatorTrackingAdapterRegistration && !m_isRegisteredScrollViewSeparatorTrackingAdapter) {
+        if ([m_view respondsToSelector:@selector(_web_registerScrollViewSeparatorTrackingAdapter)])
+            m_isRegisteredScrollViewSeparatorTrackingAdapter = [m_view _web_registerScrollViewSeparatorTrackingAdapter];
+    } else if (!wantsScrollViewSeparatorTrackingAdapterRegistration && m_isRegisteredScrollViewSeparatorTrackingAdapter) {
+        if ([m_view respondsToSelector:@selector(_web_unregisterScrollViewSeparatorTrackingAdapter)]) {
+            [m_view _web_unregisterScrollViewSeparatorTrackingAdapter];
+            m_isRegisteredScrollViewSeparatorTrackingAdapter = false;
+        }
+    }
+}
+
+#endif // HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
 NSView *WebViewImpl::hitTest(CGPoint point)
 {
     NSView *hitView = [m_view _web_superHitTest:NSPointFromCGPoint(point)];

Modified: trunk/Source/WebKit/UIProcess/PageClient.h (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/PageClient.h	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/PageClient.h	2021-01-21 15:47:16 UTC (rev 271691)
@@ -523,6 +523,8 @@
     virtual bool decidePolicyForInstallMissingMediaPluginsPermissionRequest(InstallMissingMediaPluginsPermissionRequest&) = 0;
 #endif
 
+    virtual void pageDidScroll(const WebCore::IntPoint&) { }
+
     virtual void didRestoreScrollPosition() = 0;
 
     virtual bool windowIsFrontWindowUnderMouse(const NativeWebMouseEvent&) { return false; }

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-01-21 15:47:16 UTC (rev 271691)
@@ -5851,10 +5851,12 @@
     pageClient().didChangeViewportProperties(attr);
 }
 
-void WebPageProxy::pageDidScroll()
+void WebPageProxy::pageDidScroll(const WebCore::IntPoint& scrollPosition)
 {
     m_uiClient->pageDidScroll(this);
 
+    pageClient().pageDidScroll(scrollPosition);
+
 #if PLATFORM(IOS_FAMILY)
     // Do not hide the validation message if the scrolling was caused by the keyboard showing up.
     if (m_isKeyboardAnimatingIn)

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-01-21 15:47:16 UTC (rev 271691)
@@ -1966,7 +1966,7 @@
     void rootViewToAccessibilityScreen(const WebCore::IntRect& viewRect, CompletionHandler<void(WebCore::IntRect)>&&);
     void runBeforeUnloadConfirmPanel(WebCore::FrameIdentifier, FrameInfoData&&, const String& message, Messages::WebPageProxy::RunBeforeUnloadConfirmPanelDelayedReply&&);
     void didChangeViewportProperties(const WebCore::ViewportAttributes&);
-    void pageDidScroll();
+    void pageDidScroll(const WebCore::IntPoint&);
     void runOpenPanel(WebCore::FrameIdentifier, FrameInfoData&&, const WebCore::FileChooserSettings&);
     bool didChooseFilesForOpenPanelWithImageTranscoding(const Vector<String>& fileURLs, const Vector<String>& allowedMIMETypes);
     void showShareSheet(const WebCore::ShareDataWithParsedURL&, CompletionHandler<void(bool)>&&);

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.messages.in	2021-01-21 15:47:16 UTC (rev 271691)
@@ -66,7 +66,7 @@
 #endif
 
     RunBeforeUnloadConfirmPanel(WebCore::FrameIdentifier frameID, struct WebKit::FrameInfoData frameInfo, String message) -> (bool shouldClose) Synchronous
-    PageDidScroll()
+    PageDidScroll(WebCore::IntPoint scrollPosition)
     RunOpenPanel(WebCore::FrameIdentifier frameID, struct WebKit::FrameInfoData frameInfo, struct WebCore::FileChooserSettings parameters)
     ShowShareSheet(struct WebCore::ShareDataWithParsedURL shareData) -> (bool granted) Async
     ShowContactPicker(struct WebCore::ContactsRequestData requestData) -> (Optional<Vector<WebCore::ContactInfo>> info) Async

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.h	2021-01-21 15:47:16 UTC (rev 271691)
@@ -263,6 +263,7 @@
     void refView() override;
     void derefView() override;
 
+    void pageDidScroll(const WebCore::IntPoint&) override;
     void didRestoreScrollPosition() override;
     bool windowIsFrontWindowUnderMouse(const NativeWebMouseEvent&) override;
 

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (271690 => 271691)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2021-01-21 15:47:16 UTC (rev 271691)
@@ -286,6 +286,7 @@
     m_impl->updateSupportsArbitraryLayoutModes();
     m_impl->dismissContentRelativeChildWindowsWithAnimation(true);
     m_impl->clearPromisedDragImage();
+    m_impl->pageDidScroll({0, 0});
 }
 
 void PageClientImpl::didFinishLoadingDataForCustomContentProvider(const String& suggestedFilename, const IPC::DataReference& dataReference)
@@ -939,6 +940,11 @@
     return m_impl->remoteObjectRegistry();
 }
 
+void PageClientImpl::pageDidScroll(const WebCore::IntPoint& scrollPosition)
+{
+    m_impl->pageDidScroll(scrollPosition);
+}
+
 void PageClientImpl::didRestoreScrollPosition()
 {
     m_impl->didRestoreScrollPosition();

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (271690 => 271691)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-21 15:47:16 UTC (rev 271691)
@@ -2575,7 +2575,8 @@
 
     m_pageScrolledHysteresis.impulse();
 
-    send(Messages::WebPageProxy::PageDidScroll());
+    auto scrollPosition = m_page->mainFrame().view()->scrollPosition();
+    send(Messages::WebPageProxy::PageDidScroll(scrollPosition));
 }
 
 void WebPage::pageStoppedScrolling()

Modified: trunk/Tools/ChangeLog (271690 => 271691)


--- trunk/Tools/ChangeLog	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Tools/ChangeLog	2021-01-21 15:47:16 UTC (rev 271691)
@@ -1,3 +1,27 @@
+2021-01-21  Aditya Keerthi  <akeer...@apple.com>
+
+        [macOS] Titlebar separator doesn't show when WKWebView is scrolled
+        https://bugs.webkit.org/show_bug.cgi?id=220633
+        <rdar://problem/71094055>
+
+        Reviewed by Tim Horton.
+
+        Added API tests to verify that the delegate implementation returns the
+        correct value for `hasScrolledContentsUnderTitlebar` depending on
+        the view's scroll position, visibility, and frame.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h:
+        * TestWebKitAPI/Tests/mac/WKWebViewTitlebarSeparatorTests.mm: Added.
+        (-[TitlebarSeparatorTestWKWebView initWithFrame:configuration:]):
+        (-[TitlebarSeparatorTestWKWebView separatorTrackingAdapter]):
+        (BackForwardCache):
+        (ChangeTitlebarAdjacency):
+        (ChangeViewVisibility):
+        (NavigationResetsTitlebarAppearance):
+        (ScrollWithTitlebarAdjacency):
+        (ScrollWithoutTitlebarAdjacency):
+
 2021-01-20  Jonathan Bedard  <jbed...@apple.com>
 
         [webkitscmpy] Gracefully handle missing keyring backend

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (271690 => 271691)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2021-01-21 15:47:16 UTC (rev 271691)
@@ -1105,6 +1105,7 @@
 		E3EFB02F25506503003C2F96 /* SystemBeep.mm in Sources */ = {isa = PBXBuildFile; fileRef = E3EFB02E25506503003C2F96 /* SystemBeep.mm */; };
 		E3F8AB92241AB9CE003E2A7E /* AccessibilityRemoteUIApp.mm in Sources */ = {isa = PBXBuildFile; fileRef = E3F8AB91241AB9CE003E2A7E /* AccessibilityRemoteUIApp.mm */; };
 		E5036F78211BC25400BFDBE2 /* color-drop.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = E5036F77211BC22800BFDBE2 /* color-drop.html */; };
+		E520A36B25AFB76C00526CB9 /* WKWebViewTitlebarSeparatorTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = E520A36A25AFB76C00526CB9 /* WKWebViewTitlebarSeparatorTests.mm */; };
 		E589183C252BC90A0041DED5 /* DateTimeInputsAccessoryViewTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = E589183B252BC90A0041DED5 /* DateTimeInputsAccessoryViewTests.mm */; };
 		E5AA42F2259128AE00410A3D /* UserInterfaceIdiomUpdate.mm in Sources */ = {isa = PBXBuildFile; fileRef = E5AA42F1259128AE00410A3D /* UserInterfaceIdiomUpdate.mm */; };
 		E5AA8D1D25151CC60051CC45 /* DateInputTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = E5AA8D1C25151CC60051CC45 /* DateInputTests.mm */; };
@@ -2859,6 +2860,7 @@
 		E4A757D3178AEA5B00B5D7A4 /* Deque.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Deque.cpp; sourceTree = "<group>"; };
 		E4C9ABC71B3DB1710040A987 /* RunLoop.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RunLoop.cpp; sourceTree = "<group>"; };
 		E5036F77211BC22800BFDBE2 /* color-drop.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "color-drop.html"; sourceTree = "<group>"; };
+		E520A36A25AFB76C00526CB9 /* WKWebViewTitlebarSeparatorTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewTitlebarSeparatorTests.mm; sourceTree = "<group>"; };
 		E589183B252BC90A0041DED5 /* DateTimeInputsAccessoryViewTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DateTimeInputsAccessoryViewTests.mm; sourceTree = "<group>"; };
 		E5AA42F1259128AE00410A3D /* UserInterfaceIdiomUpdate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = UserInterfaceIdiomUpdate.mm; sourceTree = "<group>"; };
 		E5AA8D1C25151CC60051CC45 /* DateInputTests.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = DateInputTests.mm; sourceTree = "<group>"; };
@@ -4576,6 +4578,7 @@
 				A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */,
 				F425831524F07CA5006B985D /* WKWebViewCoders.mm */,
 				F4FA917F1E61849B007B8C1D /* WKWebViewMacEditingTests.mm */,
+				E520A36A25AFB76C00526CB9 /* WKWebViewTitlebarSeparatorTests.mm */,
 			);
 			path = mac;
 			sourceTree = "<group>";
@@ -5687,6 +5690,7 @@
 				93F56DA91E5F919D003EDE84 /* WKWebViewSnapshot.mm in Sources */,
 				CD7F89DC22A86CDA00D683AE /* WKWebViewSuspendAllMediaPlayback.mm in Sources */,
 				9984FACC1CFFAF60008D198C /* WKWebViewTextInput.mm in Sources */,
+				E520A36B25AFB76C00526CB9 /* WKWebViewTitlebarSeparatorTests.mm in Sources */,
 				7C74C8FA22DFBA9600DA2DAB /* WTFStringUtilities.cpp in Sources */,
 				C14D304624B4C3BA00480387 /* XPCEndpoint.mm in Sources */,
 				9C64DC321D76198A004B598E /* YouTubePluginReplacement.cpp in Sources */,

Modified: trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h (271690 => 271691)


--- trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h	2021-01-21 14:25:22 UTC (rev 271690)
+++ trunk/Tools/TestWebKitAPI/Tests/TestWebKitAPI/mac/AppKitSPI.h	2021-01-21 15:47:16 UTC (rev 271691)
@@ -33,6 +33,10 @@
 #import <AppKit/NSTextInputClient_Private.h>
 #import <AppKit/NSWindow_Private.h>
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+#import <AppKit/NSScrollViewSeparatorTrackingAdapter_Private.h>
+#endif
+
 #else
 
 @protocol NSTextInputClient_Async
@@ -79,8 +83,15 @@
 - (void)setInspectorBar:(NSInspectorBar *)bar;
 @end
 
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+@protocol NSScrollViewSeparatorTrackingAdapter
+@property (readonly) NSRect scrollViewFrame;
+@property (readonly) BOOL hasScrolledContentsUnderTitlebar;
+@end
 #endif
 
+#endif
+
 @protocol NSTextInputClient_Async_Staging_44648564
 @optional
 - (void)typingAttributesWithCompletionHandler:(void(^)(NSDictionary<NSString *, id> *))completionHandler;

Added: trunk/Tools/TestWebKitAPI/Tests/mac/WKWebViewTitlebarSeparatorTests.mm (0 => 271691)


--- trunk/Tools/TestWebKitAPI/Tests/mac/WKWebViewTitlebarSeparatorTests.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/WKWebViewTitlebarSeparatorTests.mm	2021-01-21 15:47:16 UTC (rev 271691)
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2021 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. AND ITS CONTRIBUTORS ``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 ITS 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.
+ */
+
+#import "config.h"
+
+#if PLATFORM(MAC)
+
+#import "AppKitSPI.h"
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <wtf/RetainPtr.h>
+
+#if HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
+@interface TitlebarSeparatorTestWKWebView : TestWKWebView
+- (id<NSScrollViewSeparatorTrackingAdapter>)separatorTrackingAdapter;
+@end
+
+@implementation TitlebarSeparatorTestWKWebView {
+    RetainPtr<NSWindow> _hostWindow;
+}
+
+- (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration
+{
+    self = [super initWithFrame:frame configuration:configuration addToWindow:NO];
+    if (!self)
+        return nil;
+
+    [self synchronouslyLoadTestPageNamed:@"simple-tall"];
+
+    _hostWindow = adoptNS([[NSWindow alloc] initWithContentRect:self.frame styleMask:NSWindowStyleMaskTitled backing:NSBackingStoreBuffered defer:YES]);
+    [[_hostWindow contentView] addSubview:self];
+    [_hostWindow makeKeyAndOrderFront:nil];
+
+    return self;
+}
+
+- (id<NSScrollViewSeparatorTrackingAdapter>)separatorTrackingAdapter
+{
+    ASSERT([self conformsToProtocol:@protocol(NSScrollViewSeparatorTrackingAdapter)]);
+    return (id<NSScrollViewSeparatorTrackingAdapter>)self;
+}
+
+@end
+
+TEST(WKWebViewTitlebarSeparatorTests, ScrollWithTitlebarAdjacency)
+{
+    auto webView = adoptNS([[TitlebarSeparatorTestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto separatorTrackingAdapter = [webView separatorTrackingAdapter];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView stringByEvaluatingJavaScript:@"scrollTo(0, 1000)"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView stringByEvaluatingJavaScript:@"scrollTo(0, 0)"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+}
+
+TEST(WKWebViewTitlebarSeparatorTests, NavigationResetsTitlebarAppearance)
+{
+    auto webView = adoptNS([[TitlebarSeparatorTestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto separatorTrackingAdapter = [webView separatorTrackingAdapter];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView stringByEvaluatingJavaScript:@"scrollTo(0, 1000)"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView synchronouslyLoadTestPageNamed:@"simple-tall"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+}
+
+TEST(WKWebViewTitlebarSeparatorTests, ScrollWithoutTitlebarAdjacency)
+{
+    auto webView = adoptNS([[TitlebarSeparatorTestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+    [webView setFrameSize:NSMakeSize(800, 500)];
+
+    auto separatorTrackingAdapter = [webView separatorTrackingAdapter];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView stringByEvaluatingJavaScript:@"scrollTo(0, 1000)"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+}
+
+TEST(WKWebViewTitlebarSeparatorTests, ChangeTitlebarAdjacency)
+{
+    auto webView = adoptNS([[TitlebarSeparatorTestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto separatorTrackingAdapter = [webView separatorTrackingAdapter];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView stringByEvaluatingJavaScript:@"scrollTo(0, 1000)"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView setFrameSize:NSMakeSize(800, 500)];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView setFrameSize:NSMakeSize(800, 600)];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+}
+
+TEST(WKWebViewTitlebarSeparatorTests, ChangeViewVisibility)
+{
+    auto webView = adoptNS([[TitlebarSeparatorTestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto separatorTrackingAdapter = [webView separatorTrackingAdapter];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView stringByEvaluatingJavaScript:@"scrollTo(0, 1000)"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView setHidden:YES];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView setHidden:NO];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+}
+
+TEST(WKWebViewTitlebarSeparatorTests, BackForwardCache)
+{
+    auto webView = adoptNS([[TitlebarSeparatorTestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    auto separatorTrackingAdapter = [webView separatorTrackingAdapter];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView stringByEvaluatingJavaScript:@"scrollTo(0, 1000)"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView synchronouslyLoadTestPageNamed:@"simple"];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView synchronouslyGoBack];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+
+    [webView synchronouslyGoForward];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_FALSE([separatorTrackingAdapter hasScrolledContentsUnderTitlebar]);
+}
+
+#endif // HAVE(NSSCROLLVIEW_SEPARATOR_TRACKING_ADAPTER)
+
+#endif // PLATFORM(MAC)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to