Changeset 230462 in webkit


Ignore:
Timestamp:
Apr 9, 2018 6:36:29 PM (6 years ago)
Author:
timothy@apple.com
Message:

Add support for setting a background color on WKWebView and WKView
https://bugs.webkit.org/show_bug.cgi?id=184426

Reviewed by Wenson Hsieh.

Source/WebKit:

  • UIProcess/API/Cocoa/WKViewPrivate.h: Added _backgroundColor property.
  • UIProcess/API/Cocoa/WKWebView.mm:

(-[WKWebView _backgroundColor]): Added. Call through to WebViewImpl.
(-[WKWebView _setBackgroundColor:]): Added. Call through to WebViewImpl.

  • UIProcess/API/Cocoa/WKWebViewPrivate.h: Added _backgroundColor property.
  • UIProcess/API/mac/WKView.mm:

(-[WKView _backgroundColor]): Added. Call through to WebViewImpl.
(-[WKView _setBackgroundColor:]): Added. Call through to WebViewImpl.

  • UIProcess/Cocoa/WebViewImpl.h:
  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::setBackgroundColor): Added.
(WebKit::WebViewImpl::backgroundColor const): Added.
(WebKit::WebViewImpl::updateLayer): Use m_backgroundColor when set.

Tools:

  • TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
  • TestWebKitAPI/Tests/mac/BackgroundColor.mm: Added.
Location:
trunk
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r230461 r230462  
     12018-04-09  Timothy Hatcher  <timothy@apple.com>
     2
     3        Add support for setting a background color on WKWebView and WKView
     4        https://bugs.webkit.org/show_bug.cgi?id=184426
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * UIProcess/API/Cocoa/WKViewPrivate.h: Added _backgroundColor property.
     9        * UIProcess/API/Cocoa/WKWebView.mm:
     10        (-[WKWebView _backgroundColor]): Added. Call through to WebViewImpl.
     11        (-[WKWebView _setBackgroundColor:]): Added. Call through to WebViewImpl.
     12        * UIProcess/API/Cocoa/WKWebViewPrivate.h: Added _backgroundColor property.
     13        * UIProcess/API/mac/WKView.mm:
     14        (-[WKView _backgroundColor]): Added. Call through to WebViewImpl.
     15        (-[WKView _setBackgroundColor:]): Added. Call through to WebViewImpl.
     16        * UIProcess/Cocoa/WebViewImpl.h:
     17        * UIProcess/Cocoa/WebViewImpl.mm:
     18        (WebKit::WebViewImpl::setBackgroundColor): Added.
     19        (WebKit::WebViewImpl::backgroundColor const): Added.
     20        (WebKit::WebViewImpl::updateLayer): Use m_backgroundColor when set.
     21
    1222018-04-09  Yousuke Kimoto <yousuke.kimoto@sony.com> and Fujii Hironori  <Hironori.Fujii@sony.com>
    223
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKViewPrivate.h

    r230121 r230462  
    8383@property (copy, nonatomic) NSColor *underlayColor;
    8484
     85@property (nonatomic, setter=_setBackgroundColor:) NSColor *_backgroundColor;
     86
    8587#if WK_API_ENABLED
    8688@property (strong, nonatomic, setter=_setInspectorAttachmentView:) NSView *_inspectorAttachmentView WK_API_AVAILABLE(macosx(10.11));
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm

    r230440 r230462  
    55275527}
    55285528
     5529- (NSColor *)_backgroundColor
     5530{
     5531    return _impl->backgroundColor();
     5532}
     5533
     5534- (void)_setBackgroundColor:(NSColor *)backgroundColor
     5535{
     5536    _impl->setBackgroundColor(backgroundColor);
     5537}
     5538
    55295539- (void)_setDrawsTransparentBackground:(BOOL)drawsTransparentBackground
    55305540{
  • trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h

    r230121 r230462  
    261261
    262262@property (readonly) NSColor *_pageExtendedBackgroundColor;
     263@property (nonatomic, setter=_setBackgroundColor:) NSColor *_backgroundColor;
    263264@property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;
    264265@property (nonatomic, setter=_setTopContentInset:) CGFloat _topContentInset;
  • trunk/Source/WebKit/UIProcess/API/mac/WKView.mm

    r229684 r230462  
    109109{
    110110    return _data->_impl->drawsBackground();
     111}
     112
     113- (NSColor *)_backgroundColor
     114{
     115    return _data->_impl->backgroundColor();
     116}
     117
     118- (void)_setBackgroundColor:(NSColor *)backgroundColor
     119{
     120    _data->_impl->setBackgroundColor(backgroundColor);
    111121}
    112122
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h

    r229684 r230462  
    143143    void setDrawsBackground(bool);
    144144    bool drawsBackground() const;
     145    void setBackgroundColor(NSColor *);
     146    NSColor *backgroundColor() const;
    145147    bool isOpaque() const;
    146148
     
    666668    RetainPtr<NSColorSpace> m_colorSpace;
    667669
     670    RetainPtr<NSColor> m_backgroundColor;
     671
    668672    RetainPtr<NSEvent> m_lastMouseDownEvent;
    669673    RetainPtr<NSEvent> m_lastPressureEvent;
  • trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm

    r230221 r230462  
    13921392}
    13931393
     1394void WebViewImpl::setBackgroundColor(NSColor *backgroundColor)
     1395{
     1396    m_backgroundColor = backgroundColor;
     1397}
     1398
     1399NSColor *WebViewImpl::backgroundColor() const
     1400{
     1401    if (!m_backgroundColor)
     1402        return [NSColor whiteColor];
     1403    return m_backgroundColor.get();
     1404}
     1405
    13941406bool WebViewImpl::isOpaque() const
    13951407{
     
    16081620void WebViewImpl::updateLayer()
    16091621{
    1610     [m_view layer].backgroundColor = CGColorGetConstantColor(drawsBackground() ? kCGColorWhite : kCGColorClear);
     1622    bool draws = drawsBackground();
     1623    if (!draws || !m_backgroundColor)
     1624        [m_view layer].backgroundColor = CGColorGetConstantColor(draws ? kCGColorWhite : kCGColorClear);
     1625    else
     1626        [m_view layer].backgroundColor = [m_backgroundColor CGColor];
    16111627
    16121628    // If asynchronous geometry updates have been sent by forceAsyncDrawingAreaSizeUpdate,
  • trunk/Tools/ChangeLog

    r230460 r230462  
     12018-04-09  Timothy Hatcher  <timothy@apple.com>
     2
     3        Add support for setting a background color on WKWebView and WKView
     4        https://bugs.webkit.org/show_bug.cgi?id=184426
     5
     6        Reviewed by Wenson Hsieh.
     7
     8        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
     9        * TestWebKitAPI/Tests/mac/BackgroundColor.mm: Added.
     10
    1112018-04-09  Charlie Turner  <cturner@igalia.com>
    212
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r230368 r230462  
    6464                1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
    6565                1C734B5320788C4800F430EA /* SystemColors.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C734B5220788C4800F430EA /* SystemColors.mm */; };
     66                1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */; };
    6667                1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
    6768                1CAD1F861E5CE7DA00AF2C2C /* FontCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */; };
     
    11871188                1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
    11881189                1C734B5220788C4800F430EA /* SystemColors.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemColors.mm; sourceTree = "<group>"; };
     1190                1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BackgroundColor.mm; sourceTree = "<group>"; };
    11891191                1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; };
    11901192                1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCache.cpp; sourceTree = "<group>"; };
     
    29672969                                B55F119F1516834F00915916 /* AttributedString.mm */,
    29682970                                00CD9F6215BE312C002DA2CE /* BackForwardList.mm */,
     2971                                1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */,
    29692972                                26DF5A5D15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm */,
    29702973                                93CFA8681CEBCFED000565A8 /* CandidateTests.mm */,
     
    34453448                                07CD32F62065B5430064A4BE /* AVFoundationPreference.mm in Sources */,
    34463449                                7CCE7EB51A411A7E00447C4C /* BackForwardList.mm in Sources */,
     3450                                1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */,
    34473451                                374B7A601DF36EEE00ACCB6C /* BundleEditingDelegate.mm in Sources */,
    34483452                                A13EBBB11B87438000097110 /* BundleParameters.mm in Sources */,
Note: See TracChangeset for help on using the changeset viewer.