Title: [170935] trunk/Source
Revision
170935
Author
ander...@apple.com
Date
2014-07-09 15:06:29 -0700 (Wed, 09 Jul 2014)

Log Message

Support transparent WKWebViews
https://bugs.webkit.org/show_bug.cgi?id=134779
<rdar://problem/17351058>

Reviewed by Tim Horton.

Source/WebCore:
Schedule rebuilding the compositing layers if a FrameView's transparency changes.

* page/FrameView.cpp:
(WebCore::FrameView::setTransparent):

Source/WebKit2:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView initWithFrame:configuration:]):
Call _updateScrollViewBackground instead of setting the background color.

(contentZoomScale):
Use dot notation.

(scrollViewBackgroundColor):
Helper function that returns the scroll view background color.
If the web view isn't opaque, we want the scroll view to be transparent.

(-[WKWebView _updateScrollViewBackground]):
Call scrollViewBackgroundColor.

(-[WKWebView setOpaque:]):
Call WebPageProxy::setDrawsBackground and update the scroll view background.

(-[WKWebView setBackgroundColor:]):
Call setBackgroundColor on the content view.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (170934 => 170935)


--- trunk/Source/WebCore/ChangeLog	2014-07-09 21:58:13 UTC (rev 170934)
+++ trunk/Source/WebCore/ChangeLog	2014-07-09 22:06:29 UTC (rev 170935)
@@ -1,3 +1,16 @@
+2014-07-09  Anders Carlsson  <ander...@apple.com>
+
+        Support transparent WKWebViews
+        https://bugs.webkit.org/show_bug.cgi?id=134779
+        <rdar://problem/17351058>
+
+        Reviewed by Tim Horton.
+
+        Schedule rebuilding the compositing layers if a FrameView's transparency changes.
+
+        * page/FrameView.cpp:
+        (WebCore::FrameView::setTransparent):
+
 2014-07-09  Javier Fernandez  <jfernan...@igalia.com>
         CSS canvas color parsing accepts invalid color identifiers
         https://bugs.webkit.org/show_bug.cgi?id=134661

Modified: trunk/Source/WebCore/page/FrameView.cpp (170934 => 170935)


--- trunk/Source/WebCore/page/FrameView.cpp	2014-07-09 21:58:13 UTC (rev 170934)
+++ trunk/Source/WebCore/page/FrameView.cpp	2014-07-09 22:06:29 UTC (rev 170935)
@@ -2523,7 +2523,18 @@
 
 void FrameView::setTransparent(bool isTransparent)
 {
+    if (m_isTransparent == isTransparent)
+        return;
+
     m_isTransparent = isTransparent;
+
+    RenderView* renderView = this->renderView();
+    if (!renderView)
+        return;
+
+    RenderLayerCompositor& compositor = renderView->compositor();
+    compositor.setCompositingLayersNeedRebuild();
+    compositor.scheduleCompositingLayerUpdate();
 }
 
 bool FrameView::hasOpaqueBackground() const

Modified: trunk/Source/WebKit2/ChangeLog (170934 => 170935)


--- trunk/Source/WebKit2/ChangeLog	2014-07-09 21:58:13 UTC (rev 170934)
+++ trunk/Source/WebKit2/ChangeLog	2014-07-09 22:06:29 UTC (rev 170935)
@@ -1,3 +1,31 @@
+2014-07-09  Anders Carlsson  <ander...@apple.com>
+
+        Support transparent WKWebViews
+        https://bugs.webkit.org/show_bug.cgi?id=134779
+        <rdar://problem/17351058>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView initWithFrame:configuration:]):
+        Call _updateScrollViewBackground instead of setting the background color.
+
+        (contentZoomScale):
+        Use dot notation.
+
+        (scrollViewBackgroundColor):
+        Helper function that returns the scroll view background color. 
+        If the web view isn't opaque, we want the scroll view to be transparent.
+
+        (-[WKWebView _updateScrollViewBackground]):
+        Call scrollViewBackgroundColor.
+
+        (-[WKWebView setOpaque:]):
+        Call WebPageProxy::setDrawsBackground and update the scroll view background.
+
+        (-[WKWebView setBackgroundColor:]):
+        Call setBackgroundColor on the content view.
+
 2014-07-09  Andy Estes  <aes...@apple.com>
 
         [iOS] WebKit can crash under QuickLookDocumentData::encode() when viewing a QuickLook preview

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (170934 => 170935)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-07-09 21:58:13 UTC (rev 170934)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2014-07-09 22:06:29 UTC (rev 170935)
@@ -277,7 +277,6 @@
     [_scrollView setBouncesZoom:YES];
 
     [self addSubview:_scrollView.get()];
-    [_scrollView setBackgroundColor:[UIColor whiteColor]];
 
     _contentView = adoptNS([[WKContentView alloc] initWithFrame:bounds context:context configuration:WTF::move(webPageConfiguration) webView:self]);
 
@@ -287,8 +286,9 @@
 
     [_contentView layer].anchorPoint = CGPointZero;
     [_contentView setFrame:bounds];
-    [_scrollView addSubview:_contentView.get()];
     [_scrollView addSubview:[_contentView unscaledView]];
+    [self _updateScrollViewBackground];
+
     _viewportMetaTagWidth = -1;
 
     [self _frameOrBoundsChanged];
@@ -654,29 +654,40 @@
     }
 }
 
-static CGFloat contentZoomScale(WKWebView* webView)
+static CGFloat contentZoomScale(WKWebView *webView)
 {
-    CGFloat scale = [[webView._currentContentView layer] affineTransform].a;
+    CGFloat scale = webView._currentContentView.layer.affineTransform.a;
     ASSERT(scale == [webView->_scrollView zoomScale]);
     return scale;
 }
 
-- (void)_updateScrollViewBackground
+static WebCore::Color scrollViewBackgroundColor(WKWebView *webView)
 {
+    if (!webView.opaque)
+        return WebCore::Color::transparent;
+
     WebCore::Color color;
-    if (_customContentView)
-        color = [_customContentView backgroundColor].CGColor;
+
+    if (webView->_customContentView)
+        color = [webView->_customContentView backgroundColor].CGColor;
     else
-        color = _page->pageExtendedBackgroundColor();
+        color = webView->_page->pageExtendedBackgroundColor();
 
-    CGFloat zoomScale = contentZoomScale(self);
-    CGFloat minimumZoomScale = [_scrollView minimumZoomScale];
+    CGFloat zoomScale = contentZoomScale(webView);
+    CGFloat minimumZoomScale = [webView->_scrollView minimumZoomScale];
     if (zoomScale < minimumZoomScale) {
         CGFloat slope = 12;
         CGFloat opacity = std::max<CGFloat>(1 - slope * (minimumZoomScale - zoomScale), 0);
         color = WebCore::colorWithOverrideAlpha(color.rgb(), opacity);
     }
 
+    return color;
+}
+
+- (void)_updateScrollViewBackground
+{
+    WebCore::Color color = scrollViewBackgroundColor(self);
+
     if (_scrollViewBackgroundColor == color)
         return;
 
@@ -1160,6 +1171,26 @@
     _page->viewStateDidChange(WebCore::ViewState::IsInWindow);
 }
 
+- (void)setOpaque:(BOOL)opaque
+{
+    BOOL oldOpaque = self.opaque;
+
+    [super setOpaque:opaque];
+    [_contentView setOpaque:opaque];
+
+    if (oldOpaque == opaque)
+        return;
+
+    _page->setDrawsBackground(opaque);
+    [self _updateScrollViewBackground];
+}
+
+- (void)setBackgroundColor:(UIColor *)backgroundColor
+{
+    [super setBackgroundColor:backgroundColor];
+    [_contentView setBackgroundColor:backgroundColor];
+}
+
 #pragma mark - UIScrollViewDelegate
 
 - (BOOL)usesStandardContentView
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to