- Revision
- 280306
- Author
- [email protected]
- Date
- 2021-07-26 12:18:07 -0700 (Mon, 26 Jul 2021)
Log Message
[iOS] Page background color does not update after UIUserInterfaceLevel change
https://bugs.webkit.org/show_bug.cgi?id=228282
rdar://80490391
Reviewed by Wenson Hsieh.
Source/WebCore:
The default background color of the root element is a semantic color
that adapts to changes in user interface style (light/dark mode) and
user interface level (base/elevated).
Currently, the default background color is correctly recalculated
after a change to the user interface style. However, the existing
logic does not update the color unless there is a change to the user
interface style. This behavior is incorrect, since a change to the
user interface level, without a change to the user interface style,
is ignored.
A common scenario in which a user interface level change is not
accompanied by a user interface style change, is when a WKWebView is
created and then presented as a page sheet, form sheet, or popover.
In this scenario, the default background color is currently incorrect.
To fix, ensure that the background color is recalculated if any of the
traits that affect semantic colors is changed.
Test: fast/css/ios/update-user-interface-level.html
* page/FrameView.cpp:
(WebCore::FrameView::recalculateBaseBackgroundColor):
Recalculate the background color if any of the traits that affect
semantic colors is changed, not just a change in user interface
style (light/dark mode).
* page/FrameView.h:
* testing/InternalSettings.cpp:
Added a testing hook to change the current user interface level.
(WebCore::InternalSettings::resetToConsistentState):
(WebCore::InternalSettings::setUseDarkAppearance):
(WebCore::InternalSettings::setUseElevatedUserInterfaceLevel):
* testing/InternalSettings.h:
* testing/InternalSettings.idl:
LayoutTests:
Added a test to verify that a change in user interface level correctly
updates the page's background color.
* fast/css/ios/update-user-interface-level-expected.txt: Added.
* fast/css/ios/update-user-interface-level.html: Added.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (280305 => 280306)
--- trunk/LayoutTests/ChangeLog 2021-07-26 19:01:55 UTC (rev 280305)
+++ trunk/LayoutTests/ChangeLog 2021-07-26 19:18:07 UTC (rev 280306)
@@ -1,3 +1,17 @@
+2021-07-26 Aditya Keerthi <[email protected]>
+
+ [iOS] Page background color does not update after UIUserInterfaceLevel change
+ https://bugs.webkit.org/show_bug.cgi?id=228282
+ rdar://80490391
+
+ Reviewed by Wenson Hsieh.
+
+ Added a test to verify that a change in user interface level correctly
+ updates the page's background color.
+
+ * fast/css/ios/update-user-interface-level-expected.txt: Added.
+ * fast/css/ios/update-user-interface-level.html: Added.
+
2021-07-26 Ayumi Kojima <[email protected]>
[ iOS Debug] 3 editing/pasteboard/smart-paste-paragraph tests are flaky failing.
Added: trunk/LayoutTests/fast/css/ios/update-user-interface-level-expected.txt (0 => 280306)
--- trunk/LayoutTests/fast/css/ios/update-user-interface-level-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/css/ios/update-user-interface-level-expected.txt 2021-07-26 19:18:07 UTC (rev 280306)
@@ -0,0 +1,21 @@
+Test that changing the user interface level updates the page's background color.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+Dark Mode = Off, User Interface Level = Base
+PASS pageBackgroundColor is "rgb(255, 255, 255)"
+
+Dark Mode = On, User Interface Level = Base
+PASS pageBackgroundColor is "rgb(0, 0, 0)"
+
+Dark Mode = On, User Interface Level = Elevated
+PASS pageBackgroundColor is "rgb(28, 28, 30)"
+
+Dark Mode = Off, User Interface Level = Elevated
+PASS pageBackgroundColor is "rgb(255, 255, 255)"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/css/ios/update-user-interface-level.html (0 => 280306)
--- trunk/LayoutTests/fast/css/ios/update-user-interface-level.html (rev 0)
+++ trunk/LayoutTests/fast/css/ios/update-user-interface-level.html 2021-07-26 19:18:07 UTC (rev 280306)
@@ -0,0 +1,59 @@
+<html>
+<head>
+<script src=""
+<script src=""
+<style>
+
+:root {
+ color-scheme: light dark;
+}
+
+</style>
+</head>
+<body>
+</body>
+<script>
+
+jsTestIsAsync = true;
+
+addEventListener("load", async () => {
+ if (!window.internals)
+ return;
+
+ description("Test that changing the user interface level updates the page's background color.");
+
+ debug("Dark Mode = Off, User Interface Level = Base");
+ pageBackgroundColor = internals.viewBaseBackgroundColor();
+ lightModeBackgroundColor = internals.systemColorForCSSValue('-apple-system-control-background', false, false);
+ shouldBeEqualToString("pageBackgroundColor", lightModeBackgroundColor);
+ debug("");
+
+ debug("Dark Mode = On, User Interface Level = Base");
+ internals.settings.setUseDarkAppearance(true);
+ await UIHelper.renderingUpdate();
+ pageBackgroundColor = internals.viewBaseBackgroundColor();
+ darkModeBackgroundColor = internals.systemColorForCSSValue('-apple-system-control-background', true, false);
+ shouldBeEqualToString("pageBackgroundColor", darkModeBackgroundColor);
+ debug("");
+
+ debug("Dark Mode = On, User Interface Level = Elevated");
+ internals.settings.setUseElevatedUserInterfaceLevel(true);
+ await UIHelper.renderingUpdate();
+ pageBackgroundColor = internals.viewBaseBackgroundColor();
+ darkModeElevatedBackgroundColor = internals.systemColorForCSSValue('-apple-system-control-background', true, true);
+ shouldBeEqualToString("pageBackgroundColor", darkModeElevatedBackgroundColor);
+ debug("");
+
+ debug("Dark Mode = Off, User Interface Level = Elevated");
+ internals.settings.setUseDarkAppearance(false);
+ await UIHelper.renderingUpdate();
+ pageBackgroundColor = internals.viewBaseBackgroundColor();
+ lightModeElevatedBackgroundColor = internals.systemColorForCSSValue('-apple-system-control-background', false, true);
+ shouldBeEqualToString("pageBackgroundColor", lightModeElevatedBackgroundColor);
+ debug("");
+
+ finishJSTest();
+});
+
+</script>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (280305 => 280306)
--- trunk/Source/WebCore/ChangeLog 2021-07-26 19:01:55 UTC (rev 280305)
+++ trunk/Source/WebCore/ChangeLog 2021-07-26 19:18:07 UTC (rev 280306)
@@ -1,3 +1,50 @@
+2021-07-26 Aditya Keerthi <[email protected]>
+
+ [iOS] Page background color does not update after UIUserInterfaceLevel change
+ https://bugs.webkit.org/show_bug.cgi?id=228282
+ rdar://80490391
+
+ Reviewed by Wenson Hsieh.
+
+ The default background color of the root element is a semantic color
+ that adapts to changes in user interface style (light/dark mode) and
+ user interface level (base/elevated).
+
+ Currently, the default background color is correctly recalculated
+ after a change to the user interface style. However, the existing
+ logic does not update the color unless there is a change to the user
+ interface style. This behavior is incorrect, since a change to the
+ user interface level, without a change to the user interface style,
+ is ignored.
+
+ A common scenario in which a user interface level change is not
+ accompanied by a user interface style change, is when a WKWebView is
+ created and then presented as a page sheet, form sheet, or popover.
+ In this scenario, the default background color is currently incorrect.
+
+ To fix, ensure that the background color is recalculated if any of the
+ traits that affect semantic colors is changed.
+
+ Test: fast/css/ios/update-user-interface-level.html
+
+ * page/FrameView.cpp:
+ (WebCore::FrameView::recalculateBaseBackgroundColor):
+
+ Recalculate the background color if any of the traits that affect
+ semantic colors is changed, not just a change in user interface
+ style (light/dark mode).
+
+ * page/FrameView.h:
+ * testing/InternalSettings.cpp:
+
+ Added a testing hook to change the current user interface level.
+
+ (WebCore::InternalSettings::resetToConsistentState):
+ (WebCore::InternalSettings::setUseDarkAppearance):
+ (WebCore::InternalSettings::setUseElevatedUserInterfaceLevel):
+ * testing/InternalSettings.h:
+ * testing/InternalSettings.idl:
+
2021-07-26 Chris Dumez <[email protected]>
XML documents end up with a unique origin in WebKit only
Modified: trunk/Source/WebCore/page/FrameView.cpp (280305 => 280306)
--- trunk/Source/WebCore/page/FrameView.cpp 2021-07-26 19:01:55 UTC (rev 280305)
+++ trunk/Source/WebCore/page/FrameView.cpp 2021-07-26 19:18:07 UTC (rev 280306)
@@ -377,11 +377,11 @@
void FrameView::recalculateBaseBackgroundColor()
{
- bool usingDarkAppearance = useDarkAppearance();
- if (m_usesDarkAppearance == usingDarkAppearance)
+ auto styleColorOptions = this->styleColorOptions();
+ if (m_styleColorOptions == styleColorOptions)
return;
- m_usesDarkAppearance = usingDarkAppearance;
+ m_styleColorOptions = styleColorOptions;
std::optional<Color> backgroundColor;
if (m_isTransparent)
backgroundColor = Color(Color::transparentBlack);
Modified: trunk/Source/WebCore/page/FrameView.h (280305 => 280306)
--- trunk/Source/WebCore/page/FrameView.h 2021-07-26 19:01:55 UTC (rev 280305)
+++ trunk/Source/WebCore/page/FrameView.h 2021-07-26 19:18:07 UTC (rev 280306)
@@ -953,7 +953,7 @@
bool m_isTransparent { false };
#if ENABLE(DARK_MODE_CSS)
- bool m_usesDarkAppearance { false };
+ OptionSet<StyleColor::Options> m_styleColorOptions;
#endif
bool m_isTrackingRepaints { false }; // Used for testing.
Modified: trunk/Source/WebCore/testing/InternalSettings.cpp (280305 => 280306)
--- trunk/Source/WebCore/testing/InternalSettings.cpp 2021-07-26 19:01:55 UTC (rev 280305)
+++ trunk/Source/WebCore/testing/InternalSettings.cpp 2021-07-26 19:18:07 UTC (rev 280306)
@@ -187,7 +187,7 @@
m_page->setPageScaleFactor(1, { 0, 0 });
m_page->mainFrame().setPageAndTextZoomFactors(1, 1);
m_page->setCanStartMedia(true);
- setUseDarkAppearanceInternal(false);
+ m_page->effectiveAppearanceDidChange(false, false);
m_backup.restoreTo(settings());
m_backup = Backup { settings() };
@@ -521,17 +521,19 @@
return { };
}
-void InternalSettings::setUseDarkAppearanceInternal(bool useDarkAppearance)
+ExceptionOr<void> InternalSettings::setUseDarkAppearance(bool useDarkAppearance)
{
- ASSERT(m_page);
+ if (!m_page)
+ return Exception { InvalidAccessError };
m_page->effectiveAppearanceDidChange(useDarkAppearance, m_page->useElevatedUserInterfaceLevel());
+ return { };
}
-ExceptionOr<void> InternalSettings::setUseDarkAppearance(bool useDarkAppearance)
+ExceptionOr<void> InternalSettings::setUseElevatedUserInterfaceLevel(bool useElevatedUserInterfaceLevel)
{
if (!m_page)
return Exception { InvalidAccessError };
- setUseDarkAppearanceInternal(useDarkAppearance);
+ m_page->effectiveAppearanceDidChange(m_page->useDarkAppearance(), useElevatedUserInterfaceLevel);
return { };
}
Modified: trunk/Source/WebCore/testing/InternalSettings.h (280305 => 280306)
--- trunk/Source/WebCore/testing/InternalSettings.h 2021-07-26 19:01:55 UTC (rev 280305)
+++ trunk/Source/WebCore/testing/InternalSettings.h 2021-07-26 19:18:07 UTC (rev 280306)
@@ -107,6 +107,7 @@
ExceptionOr<void> setEditableRegionEnabled(bool);
ExceptionOr<void> setCanStartMedia(bool);
ExceptionOr<void> setUseDarkAppearance(bool);
+ ExceptionOr<void> setUseElevatedUserInterfaceLevel(bool);
// ScrollView
ExceptionOr<void> setAllowUnclampedScrollPosition(bool);
@@ -126,8 +127,6 @@
Settings& settings() const;
static const char* supplementName();
- void setUseDarkAppearanceInternal(bool);
-
class Backup {
public:
explicit Backup(Settings&);
Modified: trunk/Source/WebCore/testing/InternalSettings.idl (280305 => 280306)
--- trunk/Source/WebCore/testing/InternalSettings.idl 2021-07-26 19:01:55 UTC (rev 280305)
+++ trunk/Source/WebCore/testing/InternalSettings.idl 2021-07-26 19:18:07 UTC (rev 280306)
@@ -81,6 +81,7 @@
undefined setCanStartMedia(boolean enabled);
undefined setEditableRegionEnabled(boolean enabled);
undefined setUseDarkAppearance(boolean enabled);
+ undefined setUseElevatedUserInterfaceLevel(boolean enabled);
// ScrollView
undefined setAllowUnclampedScrollPosition(boolean allowUnclamped);