Setting drawsBackground to YES on a WKView doesn't take effect immediately
authortimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 May 2018 00:13:43 +0000 (00:13 +0000)
committertimothy@apple.com <timothy@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 26 May 2018 00:13:43 +0000 (00:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185885
rdar://problem/39706506

Reviewed by Simon Fraser.

Source/WebCore:

* page/Frame.cpp:
(WebCore::Frame::createView): Always call updateBackgroundRecursively, it handles
invalid colors correctly already.
* page/FrameView.cpp:
(WebCore::FrameView::setTransparent): Call setNeedsLayout() since base background color
and transparent is used to update layers.
(WebCore::FrameView::setBaseBackgroundColor): Ditto.
(WebCore::FrameView::updateBackgroundRecursively): Schedule layout if needed.
* page/FrameView.h:
* rendering/RenderLayerCompositor.cpp:
(WebCore::RenderLayerCompositor::viewHasTransparentBackground const): Use baseBackgroundColor
instead of hardcoding white.
(WebCore::RenderLayerCompositor::rootBackgroundTransparencyChanged): Fixed incorrect changed logging.

Source/WebKit:

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]): Removed setBackgroundExtendsBeyondPage(true)
since it is now the default.
* UIProcess/Cocoa/WebViewImpl.mm:
(WebKit::WebViewImpl::setDrawsBackground): Make sure updateLayer gets called on the web view
by calling setNeedsDisplay:YES.
(WebKit::WebViewImpl::setBackgroundColor): Ditto.
(WebKit::WebViewImpl::updateLayer): Removed dead code.
* UIProcess/WebPageProxy.h: Make m_backgroundExtendsBeyondPage default to true. WebKit was
always turning this on during WKWebView initializtion, which would cause the scroll
shadow layer to be created, flash black because of no background, then destroyed soon
after once WebKit's message to turn it on got delivered.
* WebProcess/WebPage/WebPage.cpp:
(WebPage::WebPage): Call setBackgroundExtendsBeyondPage earlier to avoid creating the scroll
shadow layer, since backgroundShouldExtendBeyondPage defautls to false in WebCore for WK1.
(WebKit::WebPage::setDrawsBackground): Use updateBackgroundRecursively to propagate the
correct base background color.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@232218 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/page/Frame.cpp
Source/WebCore/page/FrameView.cpp
Source/WebCore/page/FrameView.h
Source/WebCore/rendering/RenderLayerCompositor.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm
Source/WebKit/UIProcess/WebPageProxy.h
Source/WebKit/WebProcess/WebPage/WebPage.cpp

index 9300199..d967e65 100644 (file)
@@ -1,3 +1,25 @@
+2018-05-25  Timothy Hatcher  <timothy@apple.com>
+
+        Setting drawsBackground to YES on a WKView doesn't take effect immediately
+        https://bugs.webkit.org/show_bug.cgi?id=185885
+        rdar://problem/39706506
+
+        Reviewed by Simon Fraser.
+
+        * page/Frame.cpp:
+        (WebCore::Frame::createView): Always call updateBackgroundRecursively, it handles
+        invalid colors correctly already.
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setTransparent): Call setNeedsLayout() since base background color
+        and transparent is used to update layers.
+        (WebCore::FrameView::setBaseBackgroundColor): Ditto.
+        (WebCore::FrameView::updateBackgroundRecursively): Schedule layout if needed.
+        * page/FrameView.h:
+        * rendering/RenderLayerCompositor.cpp:
+        (WebCore::RenderLayerCompositor::viewHasTransparentBackground const): Use baseBackgroundColor
+        instead of hardcoding white.
+        (WebCore::RenderLayerCompositor::rootBackgroundTransparencyChanged): Fixed incorrect changed logging.
+
 2018-05-25  Youenn Fablet  <youenn@apple.com>
 
         Migrate From-Origin to Cross-Origin-Resource-Policy
index 2384861..c542b0b 100644 (file)
@@ -935,8 +935,7 @@ void Frame::createView(const IntSize& viewportSize, const Color& backgroundColor
 
     setView(frameView.copyRef());
 
-    if (backgroundColor.isValid())
-        frameView->updateBackgroundRecursively(backgroundColor, transparent);
+    frameView->updateBackgroundRecursively(backgroundColor, transparent);
 
     if (isMainFrame)
         frameView->setParentVisible(true);
index a3128d7..774be22 100644 (file)
@@ -2894,6 +2894,7 @@ void FrameView::setTransparent(bool isTransparent)
         return;
 
     renderView()->compositor().rootBackgroundTransparencyChanged();
+    setNeedsLayout();
 }
 
 bool FrameView::hasOpaqueBackground() const
@@ -2909,7 +2910,7 @@ Color FrameView::baseBackgroundColor() const
 void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
 {
     bool wasOpaque = m_baseBackgroundColor.isOpaque();
-    
+
     if (!backgroundColor.isValid())
         m_baseBackgroundColor = Color::white;
     else
@@ -2919,6 +2920,7 @@ void FrameView::setBaseBackgroundColor(const Color& backgroundColor)
         return;
 
     recalculateScrollbarOverlayStyle();
+    setNeedsLayout();
 
     if (m_baseBackgroundColor.isOpaque() != wasOpaque)
         renderView()->compositor().rootBackgroundTransparencyChanged();
@@ -2930,6 +2932,8 @@ void FrameView::updateBackgroundRecursively(const Color& backgroundColor, bool t
         if (FrameView* view = frame->view()) {
             view->setTransparent(transparent);
             view->setBaseBackgroundColor(backgroundColor);
+            if (view->needsLayout())
+                view->layoutContext().scheduleLayout();
         }
     }
 }
index 3f53901..8f60e7c 100644 (file)
@@ -187,7 +187,7 @@ public:
 
     WEBCORE_EXPORT Color baseBackgroundColor() const;
     WEBCORE_EXPORT void setBaseBackgroundColor(const Color&);
-    void updateBackgroundRecursively(const Color&, bool);
+    WEBCORE_EXPORT void updateBackgroundRecursively(const Color&, bool);
 
     enum ExtendedBackgroundModeFlags {
         ExtendedBackgroundModeNone          = 0,
index 2b1f598..b551110 100644 (file)
@@ -3084,11 +3084,13 @@ bool RenderLayerCompositor::viewHasTransparentBackground(Color* backgroundColor)
 
     Color documentBackgroundColor = m_renderView.frameView().documentBackgroundColor();
     if (!documentBackgroundColor.isValid())
-        documentBackgroundColor = Color::white;
+        documentBackgroundColor = m_renderView.frameView().baseBackgroundColor();
+
+    ASSERT(documentBackgroundColor.isValid());
 
     if (backgroundColor)
         *backgroundColor = documentBackgroundColor;
-        
+
     return !documentBackgroundColor.isOpaque();
 }
 
@@ -3120,7 +3122,7 @@ void RenderLayerCompositor::rootBackgroundTransparencyChanged()
 
     bool isTransparent = viewHasTransparentBackground();
 
-    LOG(Compositing, "RenderLayerCompositor %p rootBackgroundTransparencyChanged. isTransparent=%d, changed=%d", this, isTransparent, m_viewBackgroundIsTransparent == isTransparent);
+    LOG(Compositing, "RenderLayerCompositor %p rootBackgroundTransparencyChanged. isTransparent=%d, changed=%d", this, isTransparent, m_viewBackgroundIsTransparent != isTransparent);
     if (m_viewBackgroundIsTransparent == isTransparent)
         return;
 
index 9e8f77f..e0006fc 100644 (file)
@@ -1,3 +1,29 @@
+2018-05-25  Timothy Hatcher  <timothy@apple.com>
+
+        Setting drawsBackground to YES on a WKView doesn't take effect immediately
+        https://bugs.webkit.org/show_bug.cgi?id=185885
+        rdar://problem/39706506
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]): Removed setBackgroundExtendsBeyondPage(true)
+        since it is now the default.
+        * UIProcess/Cocoa/WebViewImpl.mm:
+        (WebKit::WebViewImpl::setDrawsBackground): Make sure updateLayer gets called on the web view
+        by calling setNeedsDisplay:YES.
+        (WebKit::WebViewImpl::setBackgroundColor): Ditto.
+        (WebKit::WebViewImpl::updateLayer): Removed dead code.
+        * UIProcess/WebPageProxy.h: Make m_backgroundExtendsBeyondPage default to true. WebKit was
+        always turning this on during WKWebView initializtion, which would cause the scroll
+        shadow layer to be created, flash black because of no background, then destroyed soon
+        after once WebKit's message to turn it on got delivered.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebPage::WebPage): Call setBackgroundExtendsBeyondPage earlier to avoid creating the scroll
+        shadow layer, since backgroundShouldExtendBeyondPage defautls to false in WebCore for WK1.
+        (WebKit::WebPage::setDrawsBackground): Use updateBackgroundRecursively to propagate the
+        correct base background color.
+
 2018-05-25  Youenn Fablet  <youenn@apple.com>
 
         Migrate From-Origin to Cross-Origin-Resource-Policy
index e988f9a..9ef6f7d 100644 (file)
@@ -702,8 +702,6 @@ static void validate(WKWebViewConfiguration *configuration)
     [self _updateAccessibilityEventsEnabled];
 #endif
 
-    _page->setBackgroundExtendsBeyondPage(true);
-
     if (NSString *applicationNameForUserAgent = configuration.applicationNameForUserAgent)
         _page->setApplicationNameForUserAgent(applicationNameForUserAgent);
 
index 591b02e..96b889b 100644 (file)
@@ -1393,6 +1393,9 @@ void WebViewImpl::didRelaunchProcess()
 void WebViewImpl::setDrawsBackground(bool drawsBackground)
 {
     m_page->setDrawsBackground(drawsBackground);
+
+    // Make sure updateLayer gets called on the web view.
+    [m_view setNeedsDisplay:YES];
 }
 
 bool WebViewImpl::drawsBackground() const
@@ -1403,6 +1406,9 @@ bool WebViewImpl::drawsBackground() const
 void WebViewImpl::setBackgroundColor(NSColor *backgroundColor)
 {
     m_backgroundColor = backgroundColor;
+
+    // Make sure updateLayer gets called on the web view.
+    [m_view setNeedsDisplay:YES];
 }
 
 NSColor *WebViewImpl::backgroundColor() const
@@ -1634,12 +1640,6 @@ void WebViewImpl::updateLayer()
         [m_view layer].backgroundColor = CGColorGetConstantColor(draws ? kCGColorWhite : kCGColorClear);
     else
         [m_view layer].backgroundColor = [m_backgroundColor CGColor];
-
-    // If asynchronous geometry updates have been sent by forceAsyncDrawingAreaSizeUpdate,
-    // then subsequent calls to setFrameSize should not result in us waiting for the did
-    // udpate response if setFrameSize is called.
-    if (frameSizeUpdatesDisabled())
-        return;
 }
 
 void WebViewImpl::drawRect(CGRect rect)
index 82e4e04..eb8efc9 100644 (file)
@@ -2077,7 +2077,7 @@ private:
     bool m_enableVerticalRubberBanding { true };
     bool m_enableHorizontalRubberBanding { true };
 
-    bool m_backgroundExtendsBeyondPage { false };
+    bool m_backgroundExtendsBeyondPage { true };
 
     bool m_shouldRecordNavigationSnapshots { false };
     bool m_isShowingNavigationGestureSnapshot { false };
index 714d0f1..f58cc94 100644 (file)
@@ -461,6 +461,8 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
     m_mainFrame = WebFrame::createWithCoreMainFrame(this, &m_page->mainFrame());
     m_drawingArea->updatePreferences(parameters.store);
 
+    setBackgroundExtendsBeyondPage(parameters.backgroundExtendsBeyondPage);
+
 #if ENABLE(GEOLOCATION)
     WebCore::provideGeolocationTo(m_page.get(), *new WebGeolocationClient(*this));
 #endif
@@ -522,8 +524,6 @@ WebPage::WebPage(uint64_t pageID, WebPageCreationParameters&& parameters)
     else
         m_scrollbarOverlayStyle = std::optional<ScrollbarOverlayStyle>();
 
-    setBackgroundExtendsBeyondPage(parameters.backgroundExtendsBeyondPage);
-
     setTopContentInset(parameters.topContentInset);
 
     m_userAgent = parameters.userAgent;
@@ -2651,9 +2651,10 @@ void WebPage::setDrawsBackground(bool drawsBackground)
 
     m_drawsBackground = drawsBackground;
 
-    for (Frame* coreFrame = m_mainFrame->coreFrame(); coreFrame; coreFrame = coreFrame->tree().traverseNext()) {
-        if (FrameView* view = coreFrame->view())
-            view->setTransparent(!drawsBackground);
+    if (FrameView* frameView = mainFrameView()) {
+        Color backgroundColor = drawsBackground ? Color::white : Color::transparent;
+        bool isTransparent = !drawsBackground;
+        frameView->updateBackgroundRecursively(backgroundColor, isTransparent);
     }
 
     m_drawingArea->pageBackgroundTransparencyChanged();