Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[MQ4] Implement update media feature
https://bugs.webkit.org/show_bug.cgi?id=180245
rdar://35799713

Reviewed by Darin Adler.

From https://drafts.csswg.org/mediaqueries/#update :
The update media feature is used to query the ability of the output device to modify the appearance of content once it has been rendered. It accepts the following values:

- none
Once it has been rendered, the layout can no longer be updated. Example: documents printed on paper.
- slow
The layout may change dynamically according to the usual rules of CSS, but the output device is not able to render or display changes quickly enough for them to be perceived as a smooth animation. Example: E-ink screens or severely under-powered devices.
- fast
The layout may change dynamically according to the usual rules of CSS, and the output device is not unusually constrained in speed, so regularly-updating things like CSS Animations can be used. Example: computer screens.

This is part of Interop 2023.

Also update overflow-block: paged to match on print mediums.

* LayoutTests/fast/css/media-query-overflow-block-paged-print-expected.html: Added.
* LayoutTests/fast/css/media-query-overflow-block-paged-print.html: Added.
* LayoutTests/fast/css/media-query-update-none-expected.html: Added.
* LayoutTests/fast/css/media-query-update-none.html: Added.
* LayoutTests/imported/w3c/web-platform-tests/css/mediaqueries/test_media_queries-expected.txt:
* Source/WebCore/css/query/MediaQueryFeatures.cpp:
(WebCore::MQ::Features::update):
(WebCore::MQ::Features::overflowBlock):
* Source/WebCore/css/query/MediaQueryFeatures.h:

Canonical link: https://commits.webkit.org/265277@main
  • Loading branch information
nt1m committed Jun 17, 2023
1 parent cab3d34 commit 777e46f
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 8 deletions.
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<html style="color: green;"><p>This text should be green in paginated mode.</p></html>
28 changes: 28 additions & 0 deletions LayoutTests/fast/css/media-query-overflow-block-paged-print.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<style>
:root {
color: blue;
}
@media (overflow-block: paged) {
:root {
color: green;
}
}
@media (overflow-block: scroll) {
:root {
color: red;
}
}
@media (overflow-block: none) {
:root {
color: red;
}
}
</style>
<p>This text should be green in paginated mode.</p>
<script>
if (window.internals)
internals.settings.setMediaTypeOverride("print");
</script>
</html>
2 changes: 2 additions & 0 deletions LayoutTests/fast/css/media-query-update-none-expected.html
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<p style="color: green">This text should be green when printing.</p>
28 changes: 28 additions & 0 deletions LayoutTests/fast/css/media-query-update-none.html
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<style>
:root {
color: blue;
}
@media (update: none) {
:root {
color: green;
}
}
@media (update: fast) {
:root {
color: red;
}
}
@media (update: slow) {
:root {
color: red;
}
}
</style>
<p>This text should be green when printing.</p>
<script>
if (window.internals)
internals.settings.setMediaTypeOverride("print");
</script>
</html>
Expand Up @@ -1270,13 +1270,13 @@ PASS expression_should_be_known: overflow-inline: scroll
PASS expression_should_be_parseable: overflow-inline: some-random-invalid-thing
PASS expression_should_be_unknown: overflow-inline: some-random-invalid-thing
PASS Sanity check for overflow-inline
FAIL expression_should_be_known: update assert_true: expected true got false
FAIL expression_should_be_known: update: none assert_true: expected true got false
FAIL expression_should_be_known: update: slow assert_true: expected true got false
FAIL expression_should_be_known: update: fast assert_true: expected true got false
PASS expression_should_be_known: update
PASS expression_should_be_known: update: none
PASS expression_should_be_known: update: slow
PASS expression_should_be_known: update: fast
PASS expression_should_be_parseable: update: some-random-invalid-thing
PASS expression_should_be_unknown: update: some-random-invalid-thing
FAIL Sanity check for update assert_not_equals: update should be equivalent to not (update: none) got disallowed value false
PASS Sanity check for update
PASS expression_should_be_known: hover
PASS expression_should_be_known: hover: hover
PASS expression_should_be_known: hover: none
Expand Down
28 changes: 25 additions & 3 deletions Source/WebCore/css/query/MediaQueryFeatures.cpp
Expand Up @@ -631,6 +631,25 @@ const FeatureSchema& transition()
return schema;
}

const FeatureSchema& update()
{
static MainThreadNeverDestroyed<IdentifierSchema> schema {
"update"_s,
Vector { CSSValueNone, CSSValueSlow, CSSValueFast },
[](auto& context) {
auto& frame = *context.document.frame();
auto* frameView = frame.view();

if (frameView && frameView->mediaType() == printAtom())
return MatchingIdentifiers { CSSValueNone };

// FIXME: Potentially add a hook for ports to change this value.
return MatchingIdentifiers { CSSValueFast };
}
};
return schema;
}

const FeatureSchema& videoPlayableInline()
{
static MainThreadNeverDestroyed<BooleanSchema> schema {
Expand Down Expand Up @@ -697,12 +716,14 @@ const FeatureSchema& overflowBlock()
Vector { CSSValueNone, CSSValueScroll, CSSValuePaged },
[](auto& context) {
// FIXME: Match none when scrollEnabled is set to false by UIKit.
bool usesPaginatedMode = [&] {
bool matchesPaged = [&] {
auto& frame = *context.document.frame();
auto* frameView = frame.view();
return frameView && frameView->pagination().mode != PaginationMode::Unpaginated;
if (!frameView)
return false;
return frameView->mediaType() == printAtom() || frameView->pagination().mode != PaginationMode::Unpaginated;
}();
return MatchingIdentifiers { usesPaginatedMode ? CSSValuePaged : CSSValueScroll };
return MatchingIdentifiers { matchesPaged ? CSSValuePaged : CSSValueScroll };
}
};
return schema;
Expand Down Expand Up @@ -771,6 +792,7 @@ Vector<const FeatureSchema*> allSchemas()
&transform2d(),
&transform3d(),
&transition(),
&update(),
&videoPlayableInline(),
&width(),
#if ENABLE(APPLICATION_MANIFEST)
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/css/query/MediaQueryFeatures.h
Expand Up @@ -60,6 +60,7 @@ const FeatureSchema& scan();
const FeatureSchema& transform2d();
const FeatureSchema& transform3d();
const FeatureSchema& transition();
const FeatureSchema& update();
const FeatureSchema& videoPlayableInline();
const FeatureSchema& width();
#if ENABLE(APPLICATION_MANIFEST)
Expand Down

0 comments on commit 777e46f

Please sign in to comment.