Changeset 170935 in webkit


Ignore:
Timestamp:
Jul 9, 2014 3:06:29 PM (10 years ago)
Author:
andersca@apple.com
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.

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r170933 r170935  
     12014-07-09  Anders Carlsson  <andersca@apple.com>
     2
     3        Support transparent WKWebViews
     4        https://bugs.webkit.org/show_bug.cgi?id=134779
     5        <rdar://problem/17351058>
     6
     7        Reviewed by Tim Horton.
     8
     9        Schedule rebuilding the compositing layers if a FrameView's transparency changes.
     10
     11        * page/FrameView.cpp:
     12        (WebCore::FrameView::setTransparent):
     13
    1142014-07-09  Javier Fernandez  <jfernandez@igalia.com>
    215        CSS canvas color parsing accepts invalid color identifiers
  • trunk/Source/WebCore/page/FrameView.cpp

    r170830 r170935  
    25242524void FrameView::setTransparent(bool isTransparent)
    25252525{
     2526    if (m_isTransparent == isTransparent)
     2527        return;
     2528
    25262529    m_isTransparent = isTransparent;
     2530
     2531    RenderView* renderView = this->renderView();
     2532    if (!renderView)
     2533        return;
     2534
     2535    RenderLayerCompositor& compositor = renderView->compositor();
     2536    compositor.setCompositingLayersNeedRebuild();
     2537    compositor.scheduleCompositingLayerUpdate();
    25272538}
    25282539
  • trunk/Source/WebKit2/ChangeLog

    r170934 r170935  
     12014-07-09  Anders Carlsson  <andersca@apple.com>
     2
     3        Support transparent WKWebViews
     4        https://bugs.webkit.org/show_bug.cgi?id=134779
     5        <rdar://problem/17351058>
     6
     7        Reviewed by Tim Horton.
     8
     9        * UIProcess/API/Cocoa/WKWebView.mm:
     10        (-[WKWebView initWithFrame:configuration:]):
     11        Call _updateScrollViewBackground instead of setting the background color.
     12
     13        (contentZoomScale):
     14        Use dot notation.
     15
     16        (scrollViewBackgroundColor):
     17        Helper function that returns the scroll view background color.
     18        If the web view isn't opaque, we want the scroll view to be transparent.
     19
     20        (-[WKWebView _updateScrollViewBackground]):
     21        Call scrollViewBackgroundColor.
     22
     23        (-[WKWebView setOpaque:]):
     24        Call WebPageProxy::setDrawsBackground and update the scroll view background.
     25
     26        (-[WKWebView setBackgroundColor:]):
     27        Call setBackgroundColor on the content view.
     28
    1292014-07-09  Andy Estes  <aestes@apple.com>
    230
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r170926 r170935  
    278278
    279279    [self addSubview:_scrollView.get()];
    280     [_scrollView setBackgroundColor:[UIColor whiteColor]];
    281280
    282281    _contentView = adoptNS([[WKContentView alloc] initWithFrame:bounds context:context configuration:WTF::move(webPageConfiguration) webView:self]);
     
    288287    [_contentView layer].anchorPoint = CGPointZero;
    289288    [_contentView setFrame:bounds];
    290     [_scrollView addSubview:_contentView.get()];
    291289    [_scrollView addSubview:[_contentView unscaledView]];
     290    [self _updateScrollViewBackground];
     291
    292292    _viewportMetaTagWidth = -1;
    293293
     
    655655}
    656656
    657 static CGFloat contentZoomScale(WKWebView* webView)
    658 {
    659     CGFloat scale = [[webView._currentContentView layer] affineTransform].a;
     657static CGFloat contentZoomScale(WKWebView *webView)
     658{
     659    CGFloat scale = webView._currentContentView.layer.affineTransform.a;
    660660    ASSERT(scale == [webView->_scrollView zoomScale]);
    661661    return scale;
    662662}
    663663
    664 - (void)_updateScrollViewBackground
    665 {
     664static WebCore::Color scrollViewBackgroundColor(WKWebView *webView)
     665{
     666    if (!webView.opaque)
     667        return WebCore::Color::transparent;
     668
    666669    WebCore::Color color;
    667     if (_customContentView)
    668         color = [_customContentView backgroundColor].CGColor;
     670
     671    if (webView->_customContentView)
     672        color = [webView->_customContentView backgroundColor].CGColor;
    669673    else
    670         color = _page->pageExtendedBackgroundColor();
    671 
    672     CGFloat zoomScale = contentZoomScale(self);
    673     CGFloat minimumZoomScale = [_scrollView minimumZoomScale];
     674        color = webView->_page->pageExtendedBackgroundColor();
     675
     676    CGFloat zoomScale = contentZoomScale(webView);
     677    CGFloat minimumZoomScale = [webView->_scrollView minimumZoomScale];
    674678    if (zoomScale < minimumZoomScale) {
    675679        CGFloat slope = 12;
     
    677681        color = WebCore::colorWithOverrideAlpha(color.rgb(), opacity);
    678682    }
     683
     684    return color;
     685}
     686
     687- (void)_updateScrollViewBackground
     688{
     689    WebCore::Color color = scrollViewBackgroundColor(self);
    679690
    680691    if (_scrollViewBackgroundColor == color)
     
    11591170{
    11601171    _page->viewStateDidChange(WebCore::ViewState::IsInWindow);
     1172}
     1173
     1174- (void)setOpaque:(BOOL)opaque
     1175{
     1176    BOOL oldOpaque = self.opaque;
     1177
     1178    [super setOpaque:opaque];
     1179    [_contentView setOpaque:opaque];
     1180
     1181    if (oldOpaque == opaque)
     1182        return;
     1183
     1184    _page->setDrawsBackground(opaque);
     1185    [self _updateScrollViewBackground];
     1186}
     1187
     1188- (void)setBackgroundColor:(UIColor *)backgroundColor
     1189{
     1190    [super setBackgroundColor:backgroundColor];
     1191    [_contentView setBackgroundColor:backgroundColor];
    11611192}
    11621193
Note: See TracChangeset for help on using the changeset viewer.