Auto merge of #29850 - servo:css-viewport-removal, r=mrobinson

CSS viewport removal

It was removed from the spec and it's disabled everywhere.

This also removes the meta viewport support (which was implemented on top), but that also had a single test and is disabled everywhere, so I'm not too concerned, it can be implemented again if / when needed.

- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #26349
- [x] There are tests for these changes
This commit is contained in:
bors-servo 2023-06-30 20:54:11 +02:00 committed by GitHub
commit 3f7e5b15f8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 35 additions and 1139 deletions

View file

@ -36,4 +36,3 @@ mod specified_values;
mod str;
mod stylesheets;
mod stylist;
mod viewport;

View file

@ -72,7 +72,6 @@ impl ParseErrorReporter for TestingErrorReporter {
#[test]
fn test_report_error_stylesheet() {
set_pref!(layout.viewport.enabled, true);
let css = r"
div {
background-color: red;
@ -88,7 +87,6 @@ fn test_report_error_stylesheet() {
@media screen { @invalid; }
@supports (color: green) and invalid and (margin: 0) {}
@keyframes foo { from invalid {} to { margin: 0 invalid 0; } }
@viewport { width: 320px invalid auto; }
";
let url = ServoUrl::parse("about::test").unwrap();
let error_reporter = TestingErrorReporter::new();
@ -135,11 +133,6 @@ fn test_report_error_stylesheet() {
52,
"Unsupported keyframe property declaration: 'margin: 0 invalid 0;'",
),
(
20,
29,
"Unsupported @viewport descriptor declaration: 'width: 320px invalid auto;'",
),
]);
assert_eq!(error_reporter.errors.borrow()[0].url, url);

View file

@ -1,629 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use cssparser::{Parser, ParserInput};
use euclid::{Scale, Size2D};
use servo_arc::Arc;
use servo_config::set_pref;
use servo_url::ServoUrl;
use style::context::QuirksMode;
use style::media_queries::{Device, MediaList, MediaType};
use style::parser::ParserContext;
use style::shared_lock::{SharedRwLock, StylesheetGuards};
use style::stylesheets::viewport_rule::*;
use style::stylesheets::{AllowImportRules, CssRuleType, Origin, Stylesheet, StylesheetInDocument};
use style::values::generics::length::LengthPercentageOrAuto::{self, Auto};
use style::values::generics::NonNegative;
use style::values::specified::LengthPercentage;
use style::values::specified::NoCalcLength::{self, ViewportPercentage};
use style::values::specified::ViewportPercentageLength::Vw;
use style_traits::viewport::*;
use style_traits::{ParsingMode, PinchZoomFactor};
macro_rules! stylesheet {
($css:expr, $origin:ident) => {
stylesheet!($css, $origin, SharedRwLock::new())
};
($css:expr, $origin:ident, $shared_lock:expr) => {
Arc::new(Stylesheet::from_str(
$css,
ServoUrl::parse("http://localhost").unwrap(),
Origin::$origin,
Arc::new($shared_lock.wrap(MediaList::empty())),
$shared_lock,
None,
None,
QuirksMode::NoQuirks,
0,
AllowImportRules::Yes,
))
};
}
fn test_viewport_rule<F>(css: &str, device: &Device, callback: F)
where
F: Fn(&Vec<ViewportDescriptorDeclaration>, &str),
{
set_pref!(layout.viewport.enabled, true);
let stylesheet = stylesheet!(css, Author);
let mut rule_count = 0;
stylesheet.effective_viewport_rules(&device, &stylesheet.shared_lock.read(), |rule| {
rule_count += 1;
callback(&rule.declarations, css);
});
assert!(rule_count > 0);
}
fn test_meta_viewport<F>(meta: &str, callback: F)
where
F: Fn(&Vec<ViewportDescriptorDeclaration>, &str),
{
if let Some(mut rule) = ViewportRule::from_meta(meta) {
// from_meta uses a hash-map to collect the declarations, so we need to
// sort them in a stable order for the tests
rule.declarations.sort_by(|a, b| {
let a = a.descriptor.discriminant_value();
let b = b.descriptor.discriminant_value();
a.cmp(&b)
});
callback(&rule.declarations, meta);
} else {
panic!("no @viewport rule for {}", meta);
}
}
macro_rules! assert_decl_len {
($declarations:ident == 1) => {
assert_eq!(
$declarations.len(),
1,
"expected 1 declaration; have {}: {:?})",
$declarations.len(),
$declarations
)
};
($declarations:ident == $len:expr) => {
assert_eq!(
$declarations.len(),
$len,
"expected {} declarations; have {}: {:?})",
$len,
$declarations.len(),
$declarations
)
};
}
macro_rules! viewport_length {
($value:expr, px) => {
ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage(NonNegative(
LengthPercentage::Length(NoCalcLength::from_px($value)),
)))
};
($value:expr, vw) => {
ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage(NonNegative(
LengthPercentage::Length(ViewportPercentage(Vw($value))),
)))
};
}
#[test]
fn empty_viewport_rule() {
let device = Device::new(
MediaType::screen(),
QuirksMode::NoQuirks,
Size2D::new(800., 600.),
Scale::new(1.0),
);
test_viewport_rule("@viewport {}", &device, |declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 0);
});
}
macro_rules! assert_decl_eq {
($d:expr, $origin:ident, $expected:ident: $value:expr) => {{
assert_eq!($d.origin, Origin::$origin);
assert_eq!($d.descriptor, ViewportDescriptor::$expected($value));
assert_eq!($d.important, false, "descriptor should not be !important");
}};
($d:expr, $origin:ident, $expected:ident: $value:expr, !important) => {{
assert_eq!($d.origin, Origin::$origin);
assert_eq!($d.descriptor, ViewportDescriptor::$expected($value));
assert_eq!($d.important, true, "descriptor should be !important");
}};
}
#[test]
fn simple_viewport_rules() {
let device = Device::new(
MediaType::screen(),
QuirksMode::NoQuirks,
Size2D::new(800., 600.),
Scale::new(1.0),
);
test_viewport_rule(
"@viewport { width: auto; height: auto;\
zoom: auto; min-zoom: 0; max-zoom: 200%;\
user-zoom: zoom; orientation: auto; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 9);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[2],
Author,
MinHeight: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[3],
Author,
MaxHeight: ViewportLength::Specified(Auto)
);
assert_decl_eq!(&declarations[4], Author, Zoom: Zoom::Auto);
assert_decl_eq!(&declarations[5], Author, MinZoom: Zoom::Number(0.));
assert_decl_eq!(&declarations[6], Author, MaxZoom: Zoom::Percentage(2.));
assert_decl_eq!(&declarations[7], Author, UserZoom: UserZoom::Zoom);
assert_decl_eq!(&declarations[8], Author, Orientation: Orientation::Auto);
},
);
test_viewport_rule(
"@viewport { min-width: 200px; max-width: auto;\
min-height: 200px; max-height: auto; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 4);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: viewport_length!(200., px)
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[2],
Author,
MinHeight: viewport_length!(200., px)
);
assert_decl_eq!(
&declarations[3],
Author,
MaxHeight: ViewportLength::Specified(Auto)
);
},
);
}
#[test]
fn simple_meta_viewport_contents() {
test_meta_viewport("width=500, height=600", |declarations, meta| {
println!("{}", meta);
assert_decl_len!(declarations == 4);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::ExtendToZoom
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: viewport_length!(500., px)
);
assert_decl_eq!(
&declarations[2],
Author,
MinHeight: ViewportLength::ExtendToZoom
);
assert_decl_eq!(
&declarations[3],
Author,
MaxHeight: viewport_length!(600., px)
);
});
test_meta_viewport("initial-scale=1.0", |declarations, meta| {
println!("{}", meta);
assert_decl_len!(declarations == 3);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::ExtendToZoom
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: ViewportLength::ExtendToZoom
);
assert_decl_eq!(&declarations[2], Author, Zoom: Zoom::Number(1.));
});
test_meta_viewport(
"initial-scale=2.0, height=device-width",
|declarations, meta| {
println!("{}", meta);
assert_decl_len!(declarations == 5);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[2],
Author,
MinHeight: ViewportLength::ExtendToZoom
);
assert_decl_eq!(
&declarations[3],
Author,
MaxHeight: viewport_length!(100., vw)
);
assert_decl_eq!(&declarations[4], Author, Zoom: Zoom::Number(2.));
},
);
test_meta_viewport(
"width=480, initial-scale=2.0, user-scalable=1",
|declarations, meta| {
println!("{}", meta);
assert_decl_len!(declarations == 4);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::ExtendToZoom
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: viewport_length!(480., px)
);
assert_decl_eq!(&declarations[2], Author, Zoom: Zoom::Number(2.));
assert_decl_eq!(&declarations[3], Author, UserZoom: UserZoom::Zoom);
},
);
}
#[test]
fn cascading_within_viewport_rule() {
let device = Device::new(
MediaType::screen(),
QuirksMode::NoQuirks,
Size2D::new(800., 600.),
Scale::new(1.0),
);
// normal order of appearance
test_viewport_rule(
"@viewport { min-width: 200px; min-width: auto; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 1);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto)
);
},
);
// !important order of appearance
test_viewport_rule(
"@viewport { min-width: 200px !important; min-width: auto !important; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 1);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto),
!important
);
},
);
// !important vs normal
test_viewport_rule(
"@viewport { min-width: auto !important; min-width: 200px; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 1);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto),
!important
);
},
);
// normal longhands vs normal shorthand
test_viewport_rule(
"@viewport { min-width: 200px; max-width: 200px; width: auto; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 2);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: ViewportLength::Specified(Auto)
);
},
);
// normal shorthand vs normal longhands
test_viewport_rule(
"@viewport { width: 200px; min-width: auto; max-width: auto; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 2);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto)
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: ViewportLength::Specified(Auto)
);
},
);
// one !important longhand vs normal shorthand
test_viewport_rule(
"@viewport { min-width: auto !important; width: 200px; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 2);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto),
!important
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: viewport_length!(200., px)
);
},
);
// both !important longhands vs normal shorthand
test_viewport_rule(
"@viewport { min-width: auto !important; max-width: auto !important; width: 200px; }",
&device,
|declarations, css| {
println!("{}", css);
assert_decl_len!(declarations == 2);
assert_decl_eq!(
&declarations[0],
Author,
MinWidth: ViewportLength::Specified(Auto),
!important
);
assert_decl_eq!(
&declarations[1],
Author,
MaxWidth: ViewportLength::Specified(Auto),
!important
);
},
);
}
#[test]
fn multiple_stylesheets_cascading() {
set_pref!(layout.viewport.enabled, true);
let device = Device::new(
MediaType::screen(),
QuirksMode::NoQuirks,
Size2D::new(800., 600.),
Scale::new(1.0),
);
let shared_lock = SharedRwLock::new();
let stylesheets = vec![
stylesheet!(
"@viewport { min-width: 100px; min-height: 100px; zoom: 1; }",
UserAgent,
shared_lock.clone()
),
stylesheet!(
"@viewport { min-width: 200px; min-height: 200px; }",
User,
shared_lock.clone()
),
stylesheet!(
"@viewport { min-width: 300px; }",
Author,
shared_lock.clone()
),
];
let declarations = Cascade::from_stylesheets(
stylesheets.iter().map(|s| (&**s, Origin::Author)),
&StylesheetGuards::same(&shared_lock.read()),
&device,
)
.finish();
assert_decl_len!(declarations == 3);
assert_decl_eq!(&declarations[0], UserAgent, Zoom: Zoom::Number(1.));
assert_decl_eq!(
&declarations[1],
User,
MinHeight: viewport_length!(200., px)
);
assert_decl_eq!(
&declarations[2],
Author,
MinWidth: viewport_length!(300., px)
);
let stylesheets = vec![
stylesheet!("@viewport { min-width: 100px !important; }",
UserAgent, shared_lock.clone()),
stylesheet!("@viewport { min-width: 200px !important; min-height: 200px !important; }",
User, shared_lock.clone()),
stylesheet!("@viewport { min-width: 300px !important; min-height: 300px !important; zoom: 3 !important; }",
Author, shared_lock.clone())
];
let declarations = Cascade::from_stylesheets(
stylesheets.iter().map(|s| (&**s, Origin::Author)),
&StylesheetGuards::same(&shared_lock.read()),
&device,
)
.finish();
assert_decl_len!(declarations == 3);
assert_decl_eq!(
&declarations[0],
UserAgent,
MinWidth: viewport_length!(100., px),
!important
);
assert_decl_eq!(
&declarations[1],
User,
MinHeight: viewport_length!(200., px),
!important
);
assert_decl_eq!(&declarations[2], Author, Zoom: Zoom::Number(3.), !important);
}
#[test]
fn constrain_viewport() {
let url = ServoUrl::parse("http://localhost").unwrap();
let context = ParserContext::new(
Origin::Author,
&url,
Some(CssRuleType::Viewport),
ParsingMode::DEFAULT,
QuirksMode::NoQuirks,
None,
None,
);
macro_rules! from_css {
($css:expr) => {
&ViewportRule::parse(&context, &mut Parser::new(&mut $css)).unwrap()
};
}
let initial_viewport = Size2D::new(800., 600.);
let device = Device::new(
MediaType::screen(),
QuirksMode::NoQuirks,
initial_viewport,
Scale::new(1.0),
);
let mut input = ParserInput::new("");
assert_eq!(
ViewportConstraints::maybe_new(&device, from_css!(input), QuirksMode::NoQuirks),
None
);
let mut input = ParserInput::new("width: 320px auto");
assert_eq!(
ViewportConstraints::maybe_new(&device, from_css!(input), QuirksMode::NoQuirks),
Some(ViewportConstraints {
size: initial_viewport,
initial_zoom: PinchZoomFactor::new(1.),
min_zoom: None,
max_zoom: None,
user_zoom: UserZoom::Zoom,
orientation: Orientation::Auto
})
);
let mut input = ParserInput::new("width: 320px auto");
assert_eq!(
ViewportConstraints::maybe_new(&device, from_css!(input), QuirksMode::NoQuirks),
Some(ViewportConstraints {
size: initial_viewport,
initial_zoom: PinchZoomFactor::new(1.),
min_zoom: None,
max_zoom: None,
user_zoom: UserZoom::Zoom,
orientation: Orientation::Auto
})
);
let mut input = ParserInput::new(
"width: 800px; height: 600px;\
zoom: 1;\
user-zoom: zoom;\
orientation: auto;",
);
assert_eq!(
ViewportConstraints::maybe_new(&device, from_css!(input), QuirksMode::NoQuirks),
Some(ViewportConstraints {
size: initial_viewport,
initial_zoom: PinchZoomFactor::new(1.),
min_zoom: None,
max_zoom: None,
user_zoom: UserZoom::Zoom,
orientation: Orientation::Auto
})
);
let initial_viewport = Size2D::new(200., 150.);
let device = Device::new(
MediaType::screen(),
QuirksMode::NoQuirks,
initial_viewport,
Scale::new(1.0),
);
let mut input = ParserInput::new("width: 320px auto");
assert_eq!(
ViewportConstraints::maybe_new(&device, from_css!(input), QuirksMode::NoQuirks),
Some(ViewportConstraints {
size: Size2D::new(320., 240.),
initial_zoom: PinchZoomFactor::new(1.),
min_zoom: None,
max_zoom: None,
user_zoom: UserZoom::Zoom,
orientation: Orientation::Auto
})
);
}

View file

@ -1,3 +0,0 @@
[meta_viewport_resize.html]
type: testharness
prefs: [layout.viewport.enabled:true]

View file

@ -1,3 +0,0 @@
prefs: [layout.viewport.enabled:true]
[viewport_meta.html]
type: reftest

View file

@ -1,3 +0,0 @@
prefs: [layout.viewport.enabled:true]
[viewport_rule.html]
type: reftest

View file

@ -6910,21 +6910,6 @@
{}
]
],
"viewport_meta.html": [
"69c57539ec5076335582a4c40fc19886b6d2620f",
[
null,
[
[
"/_mozilla/css/viewport_rule_ref.html",
"=="
]
],
{
"viewport_size": "800x600"
}
]
],
"viewport_percentage_vmin_vmax_a.html": [
"903e4ea87426e2909ee0e2b683d6f097683f5c81",
[
@ -6985,21 +6970,6 @@
}
]
],
"viewport_rule.html": [
"09d9c72a1651adf01cb14651c0eae4c5a563e682",
[
null,
[
[
"/_mozilla/css/viewport_rule_ref.html",
"=="
]
],
{
"viewport_size": "800x600"
}
]
],
"visibility_hidden.html": [
"95dbf18a0eacacb7162ab220f0d08113745efa14",
[
@ -9373,10 +9343,6 @@
"4fe2cd7165aa4832ac91493bc376b8cb3df84ab5",
[]
],
"meta_viewport_resize_iframe.html": [
"86de04da1bdc3b72e52e8f17964389a6779d7456",
[]
],
"min_max_height_b.html": [
"8723d65b2585b02664f01b84d1fda328321fc412",
[]
@ -10231,10 +10197,6 @@
"488c1aada28cc3ab41e7a6d63d3f4e5b950b1f35",
[]
],
"viewport_ignore_desktop.html.ini": [
"696f7ab3ac81362267fa882303d687cbffe454df",
[]
],
"viewport_ignore_desktop_ref.html": [
"149d364517b397c14628550e5af1c7fa37c84e90",
[]
@ -10247,10 +10209,6 @@
"07146c46a08ffe5c5e1bfd0ac451242202e93397",
[]
],
"viewport_rule_ref.html": [
"4c7be62919ac9cd9dd65861637bf10c958595e0d",
[]
],
"visibility_hidden_ref.html": [
"8f0a447ccb8175a8278438537e7597ad5116393b",
[]
@ -12564,13 +12522,6 @@
{}
]
],
"meta_viewport_resize.html": [
"7cde945198d744559f65b9a2cfb473cd02550e40",
[
null,
{}
]
],
"offset_properties_inline.html": [
"44eaa4490fc515f203c3062476121f94b4337d78",
[
@ -13480,7 +13431,7 @@
]
],
"interfaces.html": [
"b58b16ca333f9e00afade02c2ac60689ee7eef3a",
"995631527b5ab6ad2001a97574d4114576064299",
[
null,
{}

View file

@ -1,2 +0,0 @@
[viewport_meta.html]
expected: FAIL

View file

@ -1,2 +0,0 @@
[viewport_rule.html]
expected: FAIL

View file

@ -1,33 +0,0 @@
<!doctype html>
<meta charset=utf-8>
<title>Resizing the initial containing block dynamically with &lt;meta name="viewport">
https://github.com/servo/servo/issues/8443</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
async_test(function(t) {
var step2 = function() {
var iframe = document.getElementsByTagName("iframe")[0];
var body_style = iframe.contentWindow.getComputedStyle(iframe.contentDocument.body);
if (body_style.width === "500px") {
t.done();
} else {
window.requestAnimationFrame(step2);
}
};
var step1 = function() {
var iframe = document.getElementsByTagName("iframe")[0];
var body_style = iframe.contentWindow.getComputedStyle(iframe.contentDocument.body);
if (body_style.width === "400px") {
iframe.width = 500;
window.requestAnimationFrame(step2);
} else {
window.requestAnimationFrame(step1);
}
};
window.run = step1;
}, "<body> inside <iframe> has the <iframe>s width");
</script>
<iframe src="meta_viewport_resize_iframe.html" onload="run()" width=400></iframe>

View file

@ -1,4 +0,0 @@
<meta name="viewport" content="initial-scale=1.0">
<body style="margin: 0">
Test

View file

@ -1,2 +0,0 @@
prefs: ["layout.viewport.enabled:false"]

View file

@ -1,27 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel=match href=viewport_rule_ref.html>
<meta name=viewport-size content=800x600>
<meta name="viewport" content="width=240">
<style>
#container {
background: blue;
height: 100vh;
width: 100vw;
}
#box {
background: green;
height: 50vh;
width: 50vw;
}
</style>
</head>
<body>
<div id="container">
<div id="box">
</div>
</div>
</body>
</html>

View file

@ -1,31 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<link rel=match href=viewport_rule_ref.html>
<meta name=viewport-size content=800x600>
<style>
@viewport {
height: auto;
width: 240px;
}
#container {
background: blue;
height: 100vh;
width: 100vw;
}
#box {
background: green;
height: 50vh;
width: 50vw;
}
</style>
</head>
<body>
<div id="container">
<div id="box">
</div>
</div>
</body>
</html>

View file

@ -1,24 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<style>
#container {
background: blue;
height: 180px;
width: 240px;
}
#box {
background: green;
height: 90px;
width: 120px;
}
</style>
</head>
<body>
<div id="container">
<div id="box">
</div>
</div>
</body>
</html>

View file

@ -54,7 +54,6 @@ test_interfaces([
"CSSStyleRule",
"CSSStyleSheet",
"CSSSupportsRule",
"CSSViewportRule",
"DOMMatrix",
"DOMMatrixReadOnly",
"DOMPoint",