Title: [230462] trunk
Revision
230462
Author
timo...@apple.com
Date
2018-04-09 18:36:29 -0700 (Mon, 09 Apr 2018)

Log 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.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (230461 => 230462)


--- trunk/Source/WebKit/ChangeLog	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Source/WebKit/ChangeLog	2018-04-10 01:36:29 UTC (rev 230462)
@@ -1,3 +1,24 @@
+2018-04-09  Timothy Hatcher  <timo...@apple.com>
+
+        Add support for setting a background color on WKWebView and WKView
+        https://bugs.webkit.org/show_bug.cgi?id=184426
+
+        Reviewed by Wenson Hsieh.
+
+        * 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.
+
 2018-04-09  Yousuke Kimoto <yousuke.kim...@sony.com> and Fujii Hironori  <hironori.fu...@sony.com>
 
         [WinCairo] Add WebKit Shared/win event files for wincairo webkit

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKViewPrivate.h (230461 => 230462)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKViewPrivate.h	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKViewPrivate.h	2018-04-10 01:36:29 UTC (rev 230462)
@@ -82,6 +82,8 @@
 @property (readonly) NSColor *_pageExtendedBackgroundColor;
 @property (copy, nonatomic) NSColor *underlayColor;
 
+@property (nonatomic, setter=_setBackgroundColor:) NSColor *_backgroundColor;
+
 #if WK_API_ENABLED
 @property (strong, nonatomic, setter=_setInspectorAttachmentView:) NSView *_inspectorAttachmentView WK_API_AVAILABLE(macosx(10.11));
 #endif

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (230461 => 230462)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-04-10 01:36:29 UTC (rev 230462)
@@ -5526,6 +5526,16 @@
     _impl->setDrawsBackground(drawsBackground);
 }
 
+- (NSColor *)_backgroundColor
+{
+    return _impl->backgroundColor();
+}
+
+- (void)_setBackgroundColor:(NSColor *)backgroundColor
+{
+    _impl->setBackgroundColor(backgroundColor);
+}
+
 - (void)_setDrawsTransparentBackground:(BOOL)drawsTransparentBackground
 {
     static BOOL hasLoggedDeprecationWarning;

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (230461 => 230462)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2018-04-10 01:36:29 UTC (rev 230462)
@@ -260,6 +260,7 @@
 @property (nonatomic, setter=_setRubberBandingEnabled:) _WKRectEdge _rubberBandingEnabled WK_API_AVAILABLE(macosx(10.13.4));
 
 @property (readonly) NSColor *_pageExtendedBackgroundColor;
+@property (nonatomic, setter=_setBackgroundColor:) NSColor *_backgroundColor;
 @property (nonatomic, setter=_setDrawsBackground:) BOOL _drawsBackground;
 @property (nonatomic, setter=_setTopContentInset:) CGFloat _topContentInset;
 

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKView.mm (230461 => 230462)


--- trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKView.mm	2018-04-10 01:36:29 UTC (rev 230462)
@@ -110,6 +110,16 @@
     return _data->_impl->drawsBackground();
 }
 
+- (NSColor *)_backgroundColor
+{
+    return _data->_impl->backgroundColor();
+}
+
+- (void)_setBackgroundColor:(NSColor *)backgroundColor
+{
+    _data->_impl->setBackgroundColor(backgroundColor);
+}
+
 - (void)setDrawsTransparentBackground:(BOOL)drawsTransparentBackground
 {
     _data->_impl->setDrawsBackground(!drawsTransparentBackground);

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h (230461 => 230462)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.h	2018-04-10 01:36:29 UTC (rev 230462)
@@ -142,6 +142,8 @@
 
     void setDrawsBackground(bool);
     bool drawsBackground() const;
+    void setBackgroundColor(NSColor *);
+    NSColor *backgroundColor() const;
     bool isOpaque() const;
 
     void setShouldSuppressFirstResponderChanges(bool);
@@ -665,6 +667,8 @@
 
     RetainPtr<NSColorSpace> m_colorSpace;
 
+    RetainPtr<NSColor> m_backgroundColor;
+
     RetainPtr<NSEvent> m_lastMouseDownEvent;
     RetainPtr<NSEvent> m_lastPressureEvent;
 

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm (230461 => 230462)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebViewImpl.mm	2018-04-10 01:36:29 UTC (rev 230462)
@@ -1391,6 +1391,18 @@
     return m_page->drawsBackground();
 }
 
+void WebViewImpl::setBackgroundColor(NSColor *backgroundColor)
+{
+    m_backgroundColor = backgroundColor;
+}
+
+NSColor *WebViewImpl::backgroundColor() const
+{
+    if (!m_backgroundColor)
+        return [NSColor whiteColor];
+    return m_backgroundColor.get();
+}
+
 bool WebViewImpl::isOpaque() const
 {
     return m_page->drawsBackground();
@@ -1607,7 +1619,11 @@
 
 void WebViewImpl::updateLayer()
 {
-    [m_view layer].backgroundColor = CGColorGetConstantColor(drawsBackground() ? kCGColorWhite : kCGColorClear);
+    bool draws = drawsBackground();
+    if (!draws || !m_backgroundColor)
+        [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

Modified: trunk/Tools/ChangeLog (230461 => 230462)


--- trunk/Tools/ChangeLog	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Tools/ChangeLog	2018-04-10 01:36:29 UTC (rev 230462)
@@ -1,3 +1,13 @@
+2018-04-09  Timothy Hatcher  <timo...@apple.com>
+
+        Add support for setting a background color on WKWebView and WKView
+        https://bugs.webkit.org/show_bug.cgi?id=184426
+
+        Reviewed by Wenson Hsieh.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/mac/BackgroundColor.mm: Added.
+
 2018-04-09  Charlie Turner  <ctur...@igalia.com>
 
         [WPE] Add some missing install dependencies

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (230461 => 230462)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-04-10 01:33:34 UTC (rev 230461)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2018-04-10 01:36:29 UTC (rev 230462)
@@ -63,6 +63,7 @@
 		1C2B81861C89259D00A5529F /* webfont.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81841C8924A200A5529F /* webfont.html */; };
 		1C2B81871C8925A000A5529F /* Ahem.ttf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 1C2B81851C89252300A5529F /* Ahem.ttf */; };
 		1C734B5320788C4800F430EA /* SystemColors.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C734B5220788C4800F430EA /* SystemColors.mm */; };
+		1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */; };
 		1C9EB8411E380DA1005C6442 /* ComplexTextController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */; };
 		1CAD1F861E5CE7DA00AF2C2C /* FontCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */; };
 		1F83571B1D3FFB2300E3967B /* WKBackForwardList.mm in Sources */ = {isa = PBXBuildFile; fileRef = 1F83571A1D3FFB0E00E3967B /* WKBackForwardList.mm */; };
@@ -1186,6 +1187,7 @@
 		1C2B81841C8924A200A5529F /* webfont.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = webfont.html; sourceTree = "<group>"; };
 		1C2B81851C89252300A5529F /* Ahem.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = Ahem.ttf; sourceTree = "<group>"; };
 		1C734B5220788C4800F430EA /* SystemColors.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SystemColors.mm; sourceTree = "<group>"; };
+		1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BackgroundColor.mm; sourceTree = "<group>"; };
 		1C9EB8401E380DA1005C6442 /* ComplexTextController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ComplexTextController.cpp; sourceTree = "<group>"; };
 		1CAD1F851E5CE7DA00AF2C2C /* FontCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontCache.cpp; sourceTree = "<group>"; };
 		1CB9BC371A67482300FE5678 /* WeakPtr.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WeakPtr.cpp; sourceTree = "<group>"; };
@@ -2966,6 +2968,7 @@
 				379028B514FABD92007E6B43 /* AcceptsFirstMouse.mm */,
 				B55F119F1516834F00915916 /* AttributedString.mm */,
 				00CD9F6215BE312C002DA2CE /* BackForwardList.mm */,
+				1C7FEB1F207C0F2D00D23278 /* BackgroundColor.mm */,
 				26DF5A5D15A29BAA003689C2 /* CancelLoadFromResourceLoadDelegate.mm */,
 				93CFA8681CEBCFED000565A8 /* CandidateTests.mm */,
 				290A9BB51735DE8A00D71BBC /* CloseNewWindowInNavigationPolicyDelegate.mm */,
@@ -3444,6 +3447,7 @@
 				7C83E0B91D0A64F100FEBCF3 /* AutoLayoutIntegration.mm in Sources */,
 				07CD32F62065B5430064A4BE /* AVFoundationPreference.mm in Sources */,
 				7CCE7EB51A411A7E00447C4C /* BackForwardList.mm in Sources */,
+				1C7FEB20207C0F2E00D23278 /* BackgroundColor.mm in Sources */,
 				374B7A601DF36EEE00ACCB6C /* BundleEditingDelegate.mm in Sources */,
 				A13EBBB11B87438000097110 /* BundleParameters.mm in Sources */,
 				37A709AE1E3EA8B000CA5969 /* BundleRangeHandle.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/mac/BackgroundColor.mm (0 => 230462)


--- trunk/Tools/TestWebKitAPI/Tests/mac/BackgroundColor.mm	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/mac/BackgroundColor.mm	2018-04-10 01:36:29 UTC (rev 230462)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_API_ENABLED
+
+#import "PlatformUtilities.h"
+#import "TestWKWebView.h"
+#import <WebKit/WKWebViewPrivate.h>
+#import <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+TEST(WebKit, BackgroundColorDefault)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    NSColor *backgroundColor = [webView _backgroundColor];
+    EXPECT_EQ([NSColor whiteColor], backgroundColor);
+
+    // Load content so the layer is created.
+    [webView synchronouslyLoadHTMLString:@""];
+
+    EXPECT_EQ(CGColorGetConstantColor(kCGColorWhite), [webView layer].backgroundColor);
+}
+
+TEST(WebKit, BackgroundColorSystemColor)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView _setBackgroundColor:[NSColor controlBackgroundColor]];
+
+    NSColor *backgroundColor = [webView _backgroundColor];
+    EXPECT_EQ([NSColor controlBackgroundColor], backgroundColor);
+
+    // Load content so the layer is created.
+    [webView synchronouslyLoadHTMLString:@""];
+
+    EXPECT_EQ([NSColor controlBackgroundColor].CGColor, [webView layer].backgroundColor);
+}
+
+TEST(WebKit, BackgroundColorNil)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView _setBackgroundColor:nil];
+
+    NSColor *backgroundColor = [webView _backgroundColor];
+    EXPECT_EQ([NSColor whiteColor], backgroundColor);
+
+    // Load content so the layer is created.
+    [webView synchronouslyLoadHTMLString:@""];
+
+    EXPECT_EQ(CGColorGetConstantColor(kCGColorWhite), [webView layer].backgroundColor);
+}
+
+TEST(WebKit, BackgroundColorNoDrawsBackground)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView _setDrawsBackground:NO];
+
+    NSColor *backgroundColor = [webView _backgroundColor];
+    EXPECT_EQ([NSColor whiteColor], backgroundColor);
+
+    // Load content so the layer is created.
+    [webView synchronouslyLoadHTMLString:@""];
+
+    EXPECT_EQ(CGColorGetConstantColor(kCGColorClear), [webView layer].backgroundColor);
+}
+
+TEST(WebKit, BackgroundColorCustomColorNoDrawsBackground)
+{
+    auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+    [webView _setDrawsBackground:NO];
+    [webView _setBackgroundColor:[NSColor controlBackgroundColor]];
+
+    NSColor *backgroundColor = [webView _backgroundColor];
+    EXPECT_EQ([NSColor controlBackgroundColor], backgroundColor);
+
+    // Load content so the layer is created.
+    [webView synchronouslyLoadHTMLString:@""];
+
+    EXPECT_EQ(CGColorGetConstantColor(kCGColorClear), [webView layer].backgroundColor);
+}
+
+} // namespace TestWebKitAPI
+
+#endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to