Title: [265091] trunk
Revision
265091
Author
[email protected]
Date
2020-07-30 11:25:47 -0700 (Thu, 30 Jul 2020)

Log Message

Web content gets stuck in an inactive state (no cursor updates or text insertion caret) when activating a tab with a thumbnail visible
https://bugs.webkit.org/show_bug.cgi?id=214962
<rdar://problem/65670984>

Reviewed by Wenson Hsieh.

Source/WebCore:

New API test: WebKit.WKThumbnailViewResetsViewStateWhenUnparented

* testing/Internals.cpp:
(WebCore::Internals::isPageActive const):
* testing/Internals.h:
* testing/Internals.idl:
Add a "view window is active" getter.

Source/WebKit:

* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::setThumbnailView):
When WKThumbnailView is unparented, invalidate all activity state bits.
We do this because many of the functions that compute activity state bits
use the WKThumbnailView's window while it is parented. When it is unparented,
and we switch back to using the WKWebView's window, we mustn't get stuck
with activity state bits from WKThumbnailView's window.

This was particularly problematic in the case of the WKThumbnailViews
used for tab hover previews, because that window is not key, so we'd get
stuck with the inactive-window state, resulting in a lack of cursor updates,
a hidden text caret, the wrong selection color, etc.

* UIProcess/mac/PageClientImplMac.mm:
(WebKit::PageClientImpl::isViewWindowActive):
While writing the API test for this, I noticed that isViewWindowActive
returns YES if there is no key window AND WKWebView is unparented
([NSApp keyWindow] == activeWindow() == nil).
This seems completely insane (how can the window be active if it doesn't
exist?), and breaks the test, so ensure that we only say YES if we actually
have a window.

Tools:

* TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm:
(TestWebKitAPI::TEST):
Add a test ensuring that we go back to the active-window state after
unparenting a WKThumbnailView that was installed in an inactive window.

(-[WKThumbnailViewDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/mac/OffscreenWindow.h:
* TestWebKitAPI/mac/OffscreenWindow.mm:
(-[OffscreenWindow initWithSize:]):
(-[OffscreenWindow initWithSize:isKeyWindow:]):
(-[OffscreenWindow isKeyWindow]):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (265090 => 265091)


--- trunk/Source/WebCore/ChangeLog	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Source/WebCore/ChangeLog	2020-07-30 18:25:47 UTC (rev 265091)
@@ -1,3 +1,19 @@
+2020-07-30  Tim Horton  <[email protected]>
+
+        Web content gets stuck in an inactive state (no cursor updates or text insertion caret) when activating a tab with a thumbnail visible
+        https://bugs.webkit.org/show_bug.cgi?id=214962
+        <rdar://problem/65670984>
+
+        Reviewed by Wenson Hsieh.
+
+        New API test: WebKit.WKThumbnailViewResetsViewStateWhenUnparented
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::isPageActive const):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+        Add a "view window is active" getter.
+
 2020-07-30  Antoine Quint  <[email protected]>
 
         [iOS] Unable to swipe on IMDB.com after long press on image

Modified: trunk/Source/WebCore/testing/Internals.cpp (265090 => 265091)


--- trunk/Source/WebCore/testing/Internals.cpp	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Source/WebCore/testing/Internals.cpp	2020-07-30 18:25:47 UTC (rev 265091)
@@ -5171,6 +5171,15 @@
     page.setActivityState(state);
 }
 
+bool Internals::isPageActive() const
+{
+    auto* document = contextDocument();
+    if (!document || !document->page())
+        return false;
+    auto& page = *document->page();
+    return page.activityState().contains(ActivityState::WindowIsActive);
+}
+
 #if ENABLE(WEB_RTC)
 void Internals::setH264HardwareEncoderAllowed(bool allowed)
 {

Modified: trunk/Source/WebCore/testing/Internals.h (265090 => 265091)


--- trunk/Source/WebCore/testing/Internals.h	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Source/WebCore/testing/Internals.h	2020-07-30 18:25:47 UTC (rev 265091)
@@ -772,8 +772,8 @@
 
     void setPageVisibility(bool isVisible);
     void setPageIsFocusedAndActive(bool);
+    bool isPageActive() const;
 
-
 #if ENABLE(WEB_RTC)
     void setH264HardwareEncoderAllowed(bool allowed);
 #endif

Modified: trunk/Source/WebCore/testing/Internals.idl (265090 => 265091)


--- trunk/Source/WebCore/testing/Internals.idl	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Source/WebCore/testing/Internals.idl	2020-07-30 18:25:47 UTC (rev 265091)
@@ -796,6 +796,7 @@
 
     void setPageVisibility(boolean isVisible);
     void setPageIsFocusedAndActive(boolean isFocused);
+    boolean isPageActive();
 
     [Conditional=WEB_RTC] void setH264HardwareEncoderAllowed(boolean allowed);
     [Conditional=WEB_RTC] void applyRotationForOutgoingVideoSources(RTCPeerConnection connection);

Modified: trunk/Source/WebKit/ChangeLog (265090 => 265091)


--- trunk/Source/WebKit/ChangeLog	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Source/WebKit/ChangeLog	2020-07-30 18:25:47 UTC (rev 265091)
@@ -1,3 +1,33 @@
+2020-07-30  Tim Horton  <[email protected]>
+
+        Web content gets stuck in an inactive state (no cursor updates or text insertion caret) when activating a tab with a thumbnail visible
+        https://bugs.webkit.org/show_bug.cgi?id=214962
+        <rdar://problem/65670984>
+
+        Reviewed by Wenson Hsieh.
+
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::setThumbnailView):
+        When WKThumbnailView is unparented, invalidate all activity state bits.
+        We do this because many of the functions that compute activity state bits
+        use the WKThumbnailView's window while it is parented. When it is unparented,
+        and we switch back to using the WKWebView's window, we mustn't get stuck
+        with activity state bits from WKThumbnailView's window.
+
+        This was particularly problematic in the case of the WKThumbnailViews
+        used for tab hover previews, because that window is not key, so we'd get
+        stuck with the inactive-window state, resulting in a lack of cursor updates,
+        a hidden text caret, the wrong selection color, etc.
+
+        * UIProcess/mac/PageClientImplMac.mm:
+        (WebKit::PageClientImpl::isViewWindowActive):
+        While writing the API test for this, I noticed that isViewWindowActive
+        returns YES if there is no key window AND WKWebView is unparented
+        ([NSApp keyWindow] == activeWindow() == nil).
+        This seems completely insane (how can the window be active if it doesn't
+        exist?), and breaks the test, so ensure that we only say YES if we actually
+        have a window.
+
 2020-07-30  Peng Liu  <[email protected]>
 
         ASSERTION FAILED: !isInRoutingArbitrationForArbitrator(proxy) in WebKit::SharedArbitrator::beginRoutingArbitrationForArbitrator

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (265090 => 265091)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2020-07-30 18:25:47 UTC (rev 265091)
@@ -3854,8 +3854,10 @@
 
     if (thumbnailView)
         updateThumbnailViewLayer();
-    else
+    else {
         setAcceleratedCompositingRootLayer(m_rootLayer.get());
+        m_page->activityStateDidChange(WebCore::ActivityState::allFlags());
+    }
 }
 
 void WebViewImpl::reparentLayerTreeInThumbnailView()

Modified: trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm (265090 => 265091)


--- trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Source/WebKit/UIProcess/mac/PageClientImplMac.mm	2020-07-30 18:25:47 UTC (rev 265091)
@@ -160,7 +160,7 @@
 {
     ASSERT(hasProcessPrivilege(ProcessPrivilege::CanCommunicateWithWindowServer));
     NSWindow *activeViewWindow = activeWindow();
-    return activeViewWindow.isKeyWindow || [NSApp keyWindow] == activeViewWindow;
+    return activeViewWindow.isKeyWindow || (activeViewWindow && [NSApp keyWindow] == activeViewWindow);
 }
 
 bool PageClientImpl::isViewFocused()

Modified: trunk/Tools/ChangeLog (265090 => 265091)


--- trunk/Tools/ChangeLog	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Tools/ChangeLog	2020-07-30 18:25:47 UTC (rev 265091)
@@ -1,3 +1,23 @@
+2020-07-30  Tim Horton  <[email protected]>
+
+        Web content gets stuck in an inactive state (no cursor updates or text insertion caret) when activating a tab with a thumbnail visible
+        https://bugs.webkit.org/show_bug.cgi?id=214962
+        <rdar://problem/65670984>
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm:
+        (TestWebKitAPI::TEST):
+        Add a test ensuring that we go back to the active-window state after
+        unparenting a WKThumbnailView that was installed in an inactive window.
+
+        (-[WKThumbnailViewDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/mac/OffscreenWindow.h:
+        * TestWebKitAPI/mac/OffscreenWindow.mm:
+        (-[OffscreenWindow initWithSize:]):
+        (-[OffscreenWindow initWithSize:isKeyWindow:]):
+        (-[OffscreenWindow isKeyWindow]):
+
 2020-07-30  Jonathan Bedard  <[email protected]>
 
         [Big Sur] Add limited Seed 3 support to EWS

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm (265090 => 265091)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit/WKThumbnailView.mm	2020-07-30 18:25:47 UTC (rev 265091)
@@ -28,9 +28,11 @@
 #if PLATFORM(MAC)
 
 #import "_javascript_Test.h"
+#import "OffscreenWindow.h"
 #import "PlatformUtilities.h"
 #import "PlatformWebView.h"
 #import "TestWKWebView.h"
+#import "WKWebViewConfigurationExtras.h"
 #import <WebKit/WKViewPrivate.h>
 #import <WebKit/_WKThumbnailView.h>
 #import <wtf/RetainPtr.h>
@@ -61,19 +63,6 @@
 
 @end
 
-
-@interface WKThumbnailViewDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation WKThumbnailViewDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    didFinishLoad = true;
-}
-
-@end
-
 namespace TestWebKitAPI {
 
 #if WK_HAVE_C_SPI
@@ -199,10 +188,7 @@
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
     WKPageSetCustomBackingScaleFactor([webView _pageForTesting], 1);
-    auto delegate = adoptNS([[WKThumbnailViewDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-    [webView  loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
-    Util::run(&didFinishLoad);
+    [webView synchronouslyLoadTestPageNamed:@"lots-of-text"];
 
     RetainPtr<_WKThumbnailView> thumbnailView = adoptNS([[_WKThumbnailView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) fromWKWebView:webView.get()]);
     
@@ -241,10 +227,7 @@
 {
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600)]);
     WKPageSetCustomBackingScaleFactor([webView _pageForTesting], 1);
-    auto delegate = adoptNS([[WKThumbnailViewDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-    [webView  loadRequest:[NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]];
-    Util::run(&didFinishLoad);
+    [webView synchronouslyLoadTestPageNamed:@"lots-of-text"];
 
     auto thumbnailView = adoptNS([[_WKThumbnailView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) fromWKWebView:webView.get()]);
 
@@ -285,6 +268,41 @@
     [thumbnailView removeObserver:observer.get() forKeyPath:@"snapshotSize" context:snapshotSizeChangeKVOContext];
 }
 
+TEST(WebKit, WKThumbnailViewResetsViewStateWhenUnparented)
+{
+    WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"WebProcessPlugInWithInternals" configureJSCForTesting:YES];
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration]);
+    [webView removeFromSuperview];
+    [webView synchronouslyLoadTestPageNamed:@"lots-of-text"];
+
+    auto thumbnailView = adoptNS([[_WKThumbnailView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) fromWKWebView:webView.get()]);
+
+    auto observer = adoptNS([[SnapshotSizeObserver alloc] init]);
+
+    [thumbnailView addObserver:observer.get() forKeyPath:@"snapshotSize" options:NSKeyValueObservingOptionNew context:snapshotSizeChangeKVOContext];
+
+    RetainPtr<NSWindow> otherWindow = adoptNS([[OffscreenWindow alloc] initWithSize:CGSizeMake(100, 100) isKeyWindow:NO]);
+    [[otherWindow contentView] addSubview:thumbnailView.get()];
+    [otherWindow orderFront:nil];
+    [[webView hostWindow] makeKeyAndOrderFront:nil];
+    Util::run(&didTakeSnapshot);
+    didTakeSnapshot = false;
+    EXPECT_FALSE([thumbnailView layer].contents == nil);
+    [webView waitForNextPresentationUpdate];
+    EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"window.internals.isPageActive()"] boolValue]);
+
+    [webView addToTestWindow];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_FALSE([[webView objectByEvaluatingJavaScript:@"window.internals.isPageActive()"] boolValue]);
+
+    [thumbnailView removeFromSuperview];
+    [webView waitForNextPresentationUpdate];
+    EXPECT_TRUE([[webView objectByEvaluatingJavaScript:@"window.internals.isPageActive()"] boolValue]);
+
+    [thumbnailView removeObserver:observer.get() forKeyPath:@"snapshotSize" context:snapshotSizeChangeKVOContext];
+}
+
+
 } // namespace TestWebKitAPI
 
-#endif
+#endif // PLATFORM(MAC)

Modified: trunk/Tools/TestWebKitAPI/mac/OffscreenWindow.h (265090 => 265091)


--- trunk/Tools/TestWebKitAPI/mac/OffscreenWindow.h	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Tools/TestWebKitAPI/mac/OffscreenWindow.h	2020-07-30 18:25:47 UTC (rev 265091)
@@ -34,6 +34,7 @@
 - (instancetype)initWithContentRect:(NSRect)contentRect styleMask:(NSWindowStyleMask)style backing:(NSBackingStoreType)backingStoreType defer:(BOOL)flag screen:(NSScreen *)screen NS_UNAVAILABLE;
 
 - (instancetype)initWithSize:(CGSize)size;
+- (instancetype)initWithSize:(CGSize)size isKeyWindow:(BOOL)isKeyWindow;
 
 @end
 

Modified: trunk/Tools/TestWebKitAPI/mac/OffscreenWindow.mm (265090 => 265091)


--- trunk/Tools/TestWebKitAPI/mac/OffscreenWindow.mm	2020-07-30 18:20:56 UTC (rev 265090)
+++ trunk/Tools/TestWebKitAPI/mac/OffscreenWindow.mm	2020-07-30 18:25:47 UTC (rev 265091)
@@ -26,10 +26,19 @@
 #import "config.h"
 #import "OffscreenWindow.h"
 
-@implementation OffscreenWindow
+@implementation OffscreenWindow {
+    BOOL _isKeyWindow;
+}
 
 - (instancetype)initWithSize:(CGSize)size
 {
+    return [self initWithSize:size isKeyWindow:YES];
+}
+
+- (instancetype)initWithSize:(CGSize)size isKeyWindow:(BOOL)isKeyWindow
+{
+    _isKeyWindow = isKeyWindow;
+
     NSRect rect = NSMakeRect(0, 0, size.width, size.height);
     NSRect windowRect = NSOffsetRect(rect, -10000, [(NSScreen *)[[NSScreen screens] objectAtIndex:0] frame].size.height - rect.size.height + 10000);
     self = [super initWithContentRect:windowRect styleMask:NSWindowStyleMaskBorderless backing:NSBackingStoreBuffered defer:YES];
@@ -46,7 +55,7 @@
 
 - (BOOL)isKeyWindow
 {
-    return YES;
+    return _isKeyWindow;
 }
 
 - (BOOL)isVisible
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to