haikuwebkit/LayoutTests/css-dark-mode/prefers-color-scheme-pictur...

32 lines
955 B
HTML
Raw Permalink Normal View History

<picture> container doesn't update when prefers-color-scheme media query changes https://bugs.webkit.org/show_bug.cgi?id=190913 rdar://problem/45608456 Reviewed by Dean Jackson. Source/WebCore: Test: css-dark-mode/prefers-color-scheme-picture-element.html * css/MediaQueryEvaluator.cpp: (WebCore::isAppearanceDependent): Added. (WebCore::MediaQueryEvaluator::evaluate const): Keep track of appearanceDependentResults. * css/MediaQueryEvaluator.h: * css/StyleResolver.cpp: (WebCore::StyleResolver::addAppearanceDependentMediaQueryResult): Added. (WebCore::StyleResolver::hasMediaQueriesAffectedByAppearanceChange const): Added. * css/StyleResolver.h: (WebCore::StyleResolver::hasAppearanceDependentMediaQueries const): Added. * dom/Document.cpp: (WebCore::Document::evaluateMediaQueryList): Call checkAppearanceDependentPictures. (WebCore::Document::checkAppearanceDependentPictures): Added. (WebCore::Document::addAppearanceDependentPicture): Added. (WebCore::Document::removeAppearanceDependentPicture): Added. * dom/Document.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): Call addAppearanceDependentPicture. * html/HTMLPictureElement.cpp: (WebCore::HTMLPictureElement::~HTMLPictureElement): Call removeAppearanceDependentPicture. (WebCore::HTMLPictureElement::didMoveToNewDocument): Ditto. (WebCore::HTMLPictureElement::appearanceChangeAffectedPicture const): Added. * html/HTMLPictureElement.h: * page/Page.cpp: (WebCore::Page::appearanceDidChange): Added. (WebCore::Page::setUseSystemAppearance): Call appearanceDidChange. (WebCore::Page::setUseDarkAppearance): Call appearanceDidChange. * page/Page.h: * style/StyleScope.cpp: (WebCore::Style::Scope::evaluateMediaQueriesForAppearanceChange): Added. * style/StyleScope.h: LayoutTests: * css-dark-mode/prefers-color-scheme-picture-element-expected.txt: Added. * css-dark-mode/prefers-color-scheme-picture-element.html: Added. * platform/mac-highsierra/css-dark-mode/prefers-color-scheme-picture-element-expected.txt: Added. * platform/mac-sierra/css-dark-mode/prefers-color-scheme-picture-element-expected.txt: Added. Canonical link: https://commits.webkit.org/206121@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@237878 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2018-11-06 19:53:13 +00:00
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<picture id="test1">
<source srcset="dark.png" media="(prefers-color-scheme: dark)">
<source srcset="light.png" media="(prefers-color-scheme: light)">
<img src="error.png">
</picture>
<script>
function test_picture(id, expected) {
assert_regexp_match(document.getElementById(id).querySelector("img").currentSrc, new RegExp(`/${expected}$`));
}
test(function() {
// The current image should be the light source.
test_picture("test1", "light.png");
}, "Picture image has the light source selected");
test(function() {
if (window.internals)
internals.settings.setUseDarkAppearance(true);
}, "Dark color scheme enabled");
test(function() {
// The current image should be the dark source.
test_picture("test1", "dark.png");
}, "Picture image has the dark source selected");
</script>