- Revision
- 280283
- Author
- [email protected]
- Date
- 2021-07-24 01:20:05 -0700 (Sat, 24 Jul 2021)
Log Message
[iOS] REGRESSION(r277505): `-[WKWebView underPageBackgroundColor]` also changes the scroll bar color
https://bugs.webkit.org/show_bug.cgi?id=228259
<rdar://problem/80116822>
Reviewed by Tim Horton.
Source/WebKit:
If an application overrides the `-underPageBackgroundColor` with a dark color on a page that
has a light background color, the scroll bar will appear light to match the overridden value
of `-underPageBackgroundColor` instead of dark to match the page's background color.
Test: WKWebViewUnderPageBackgroundColor.MatchesScrollView
* UIProcess/API/ios/WKWebViewIOS.mm:
(baseScrollViewBackgroundColor):
(scrollViewBackgroundColor):
(-[WKWebView _updateScrollViewBackground]):
Add a flag to indicate whether the `underPageBackgroundColor` (which can be overridden by
API) or `pageExtendedBackgroundColor` should be used when calculating the value provided to
`-[UIScrollView setBackgroundColor:]` and `-[UIScrollView setIndicatorStyle:]`. The former
uses the `underPageBackgroundColor` since that is why that API exists and the latter uses
the ``pageExtendedBackgroundColor` since it is based on what is shown in the page, which is
what the scroll bar is drawn on top of.
Tools:
* TestWebKitAPI/Tests/WebKitCocoa/WKWebViewUnderPageBackgroundColor.mm:
(TEST.WKWebViewUnderPageBackgroundColor.MatchesScrollView):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (280282 => 280283)
--- trunk/Source/WebKit/ChangeLog 2021-07-24 03:48:01 UTC (rev 280282)
+++ trunk/Source/WebKit/ChangeLog 2021-07-24 08:20:05 UTC (rev 280283)
@@ -1,3 +1,28 @@
+2021-07-24 Devin Rousso <[email protected]>
+
+ [iOS] REGRESSION(r277505): `-[WKWebView underPageBackgroundColor]` also changes the scroll bar color
+ https://bugs.webkit.org/show_bug.cgi?id=228259
+ <rdar://problem/80116822>
+
+ Reviewed by Tim Horton.
+
+ If an application overrides the `-underPageBackgroundColor` with a dark color on a page that
+ has a light background color, the scroll bar will appear light to match the overridden value
+ of `-underPageBackgroundColor` instead of dark to match the page's background color.
+
+ Test: WKWebViewUnderPageBackgroundColor.MatchesScrollView
+
+ * UIProcess/API/ios/WKWebViewIOS.mm:
+ (baseScrollViewBackgroundColor):
+ (scrollViewBackgroundColor):
+ (-[WKWebView _updateScrollViewBackground]):
+ Add a flag to indicate whether the `underPageBackgroundColor` (which can be overridden by
+ API) or `pageExtendedBackgroundColor` should be used when calculating the value provided to
+ `-[UIScrollView setBackgroundColor:]` and `-[UIScrollView setIndicatorStyle:]`. The former
+ uses the `underPageBackgroundColor` since that is why that API exists and the latter uses
+ the ``pageExtendedBackgroundColor` since it is based on what is shown in the page, which is
+ what the scroll bar is drawn on top of.
+
2021-07-23 Alex Christensen <[email protected]>
Make WKContentRuleListStore respond to same selectors as _WKUserContentExtensionStore
Modified: trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm (280282 => 280283)
--- trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2021-07-24 03:48:01 UTC (rev 280282)
+++ trunk/Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm 2021-07-24 08:20:05 UTC (rev 280283)
@@ -476,7 +476,9 @@
return scale;
}
-static WebCore::Color baseScrollViewBackgroundColor(WKWebView *webView)
+enum class AllowPageBackgroundColorOverride : bool { No, Yes };
+
+static WebCore::Color baseScrollViewBackgroundColor(WKWebView *webView, AllowPageBackgroundColorOverride allowPageBackgroundColorOverride)
{
if (webView->_customContentView)
return [webView->_customContentView backgroundColor].CGColor;
@@ -490,10 +492,10 @@
if (!webView->_page)
return { };
- return webView->_page->underPageBackgroundColor();
+ return allowPageBackgroundColorOverride == AllowPageBackgroundColorOverride::Yes ? webView->_page->underPageBackgroundColor() : webView->_page->pageExtendedBackgroundColor();
}
-static WebCore::Color scrollViewBackgroundColor(WKWebView *webView)
+static WebCore::Color scrollViewBackgroundColor(WKWebView *webView, AllowPageBackgroundColorOverride allowPageBackgroundColorOverride)
{
if (!webView.opaque)
return WebCore::Color::transparentBlack;
@@ -502,7 +504,7 @@
WebCore::LocalCurrentTraitCollection localTraitCollection(webView.traitCollection);
#endif
- WebCore::Color color = baseScrollViewBackgroundColor(webView);
+ WebCore::Color color = baseScrollViewBackgroundColor(webView, allowPageBackgroundColorOverride);
if (!color.isValid() && webView->_contentView)
color = [webView->_contentView backgroundColor].CGColor;
@@ -528,18 +530,17 @@
- (void)_updateScrollViewBackground
{
- WebCore::Color color = scrollViewBackgroundColor(self);
+ auto newScrollViewBackgroundColor = scrollViewBackgroundColor(self, AllowPageBackgroundColorOverride::Yes);
+ if (_scrollViewBackgroundColor != newScrollViewBackgroundColor) {
+ _scrollViewBackgroundColor = newScrollViewBackgroundColor;
- if (_scrollViewBackgroundColor == color)
- return;
+ auto uiBackgroundColor = adoptNS([[UIColor alloc] initWithCGColor:cachedCGColor(newScrollViewBackgroundColor)]);
+ [_scrollView setBackgroundColor:uiBackgroundColor.get()];
+ }
- _scrollViewBackgroundColor = color;
-
- auto uiBackgroundColor = adoptNS([[UIColor alloc] initWithCGColor:cachedCGColor(color)]);
- [_scrollView setBackgroundColor:uiBackgroundColor.get()];
-
// Update the indicator style based on the lightness/darkness of the background color.
- if (color.lightness() <= .5f && color.isVisible())
+ auto newPageBackgroundColor = scrollViewBackgroundColor(self, AllowPageBackgroundColorOverride::No);
+ if (newPageBackgroundColor.lightness() <= .5f && newPageBackgroundColor.isVisible())
[_scrollView setIndicatorStyle:UIScrollViewIndicatorStyleWhite];
else
[_scrollView setIndicatorStyle:UIScrollViewIndicatorStyleBlack];
Modified: trunk/Tools/ChangeLog (280282 => 280283)
--- trunk/Tools/ChangeLog 2021-07-24 03:48:01 UTC (rev 280282)
+++ trunk/Tools/ChangeLog 2021-07-24 08:20:05 UTC (rev 280283)
@@ -1,3 +1,14 @@
+2021-07-24 Devin Rousso <[email protected]>
+
+ [iOS] REGRESSION(r277505): `-[WKWebView underPageBackgroundColor]` also changes the scroll bar color
+ https://bugs.webkit.org/show_bug.cgi?id=228259
+ <rdar://problem/80116822>
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/WKWebViewUnderPageBackgroundColor.mm:
+ (TEST.WKWebViewUnderPageBackgroundColor.MatchesScrollView):
+
2021-07-23 Andres Gonzalez <[email protected]>
Add a method to WebAccessibilityObjectWrapper so that clients can retrieve the text of each line and their corresponding bounding rectangles.
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewUnderPageBackgroundColor.mm (280282 => 280283)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewUnderPageBackgroundColor.mm 2021-07-24 03:48:01 UTC (rev 280282)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewUnderPageBackgroundColor.mm 2021-07-24 08:20:05 UTC (rev 280283)
@@ -276,6 +276,8 @@
#if PLATFORM(IOS_FAMILY)
+constexpr CGFloat whiteColorComponents[4] = { 1, 1, 1, 1 };
+
// There's no API/SPI to get the background color of the scroll area on macOS.
TEST(WKWebViewUnderPageBackgroundColor, MatchesScrollView)
@@ -283,6 +285,7 @@
auto sRGBColorSpace = adoptCF(CGColorSpaceCreateWithName(kCGColorSpaceSRGB));
auto redColor = adoptCF(CGColorCreate(sRGBColorSpace.get(), redColorComponents));
auto blueColor = adoptCF(CGColorCreate(sRGBColorSpace.get(), blueColorComponents));
+ auto whiteColor = adoptCF(CGColorCreate(sRGBColorSpace.get(), whiteColorComponents));
auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
EXPECT_TRUE(CGColorEqualToColor([webView underPageBackgroundColor].CGColor, defaultBackgroundColor().get()));
@@ -291,11 +294,19 @@
[webView synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:@"<style> body { background-color: red; } </style>"];
EXPECT_TRUE(CGColorEqualToColor([webView underPageBackgroundColor].CGColor, redColor.get()));
EXPECT_TRUE(CGColorEqualToColor([webView scrollView].backgroundColor.CGColor, redColor.get()));
+ EXPECT_EQ([webView scrollView].indicatorStyle, UIScrollViewIndicatorStyleWhite);
[webView setUnderPageBackgroundColor:[CocoaColor colorWithCGColor:blueColor.get()]];
[webView waitForNextPresentationUpdate];
EXPECT_TRUE(CGColorEqualToColor([webView underPageBackgroundColor].CGColor, blueColor.get()));
EXPECT_TRUE(CGColorEqualToColor([webView scrollView].backgroundColor.CGColor, blueColor.get()));
+ EXPECT_EQ([webView scrollView].indicatorStyle, UIScrollViewIndicatorStyleWhite);
+
+ [webView setUnderPageBackgroundColor:[CocoaColor colorWithCGColor:whiteColor.get()]];
+ [webView waitForNextPresentationUpdate];
+ EXPECT_TRUE(CGColorEqualToColor([webView underPageBackgroundColor].CGColor, whiteColor.get()));
+ EXPECT_TRUE(CGColorEqualToColor([webView scrollView].backgroundColor.CGColor, whiteColor.get()));
+ EXPECT_EQ([webView scrollView].indicatorStyle, UIScrollViewIndicatorStyleWhite);
}
#endif // PLATFORM(IOS_FAMILY)