Backed out 1 changesets (bug 1766020) for bc failures on browser_modal_print.js . CLOSED TREE

Backed out changeset 10118450bd7f (bug 1766020)
This commit is contained in:
Narcis Beleuzu 2022-04-27 12:34:31 +03:00
parent 1a1a09d2c6
commit fc786a2667
17 changed files with 141 additions and 232 deletions

View file

@ -7,7 +7,6 @@
use crate::gecko_bindings::bindings;
use crate::gecko_bindings::structs;
use crate::queries::feature::{AllowsRanges, Evaluator, ParsingRequirements, QueryFeatureDescription};
use crate::queries::values::Orientation;
use crate::media_queries::{Device, MediaType};
use crate::values::computed::{Context, CSSPixelLength, Ratio, Resolution};
use app_units::Au;
@ -65,14 +64,40 @@ fn eval_device_pixel_ratio(context: &Context) -> f32 {
eval_resolution(context).dppx()
}
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
#[repr(u8)]
enum Orientation {
Landscape,
Portrait,
}
fn eval_orientation_for<F>(context: &Context, value: Option<Orientation>, get_size: F) -> bool
where
F: FnOnce(&Device) -> Size2D<Au>,
{
let query_orientation = match value {
Some(v) => v,
None => return true,
};
let size = get_size(context.device());
// Per spec, square viewports should be 'portrait'
let is_landscape = size.width > size.height;
match query_orientation {
Orientation::Landscape => is_landscape,
Orientation::Portrait => !is_landscape,
}
}
/// https://drafts.csswg.org/mediaqueries-4/#orientation
fn eval_orientation(context: &Context, value: Option<Orientation>) -> bool {
Orientation::eval(context.device().au_viewport_size(), value)
eval_orientation_for(context, value, Device::au_viewport_size)
}
/// FIXME: There's no spec for `-moz-device-orientation`.
fn eval_device_orientation(context: &Context, value: Option<Orientation>) -> bool {
Orientation::eval(device_size(context.device()), value)
eval_orientation_for(context, value, device_size)
}
/// Values for the display-mode media feature.

View file

@ -872,10 +872,10 @@ impl<T> LogicalMargin<T> {
inline_start: T,
) -> LogicalMargin<T> {
LogicalMargin {
block_start,
inline_end,
block_end,
inline_start,
block_start: block_start,
inline_end: inline_end,
block_end: block_end,
inline_start: inline_start,
debug_writing_mode: DebugWritingMode::new(mode),
}
}

View file

@ -6,7 +6,7 @@
//!
//! https://drafts.csswg.org/mediaqueries/#typedef-media-query
use crate::queries::{QueryCondition, FeatureType};
use crate::queries::QueryCondition;
use crate::parser::ParserContext;
use crate::str::string_as_ascii_lowercase;
use crate::values::CustomIdent;
@ -134,9 +134,9 @@ impl MediaQuery {
.unwrap_or_default();
let condition = if explicit_media_type.is_none() {
Some(QueryCondition::parse(context, input, FeatureType::Media)?)
Some(QueryCondition::parse(context, input)?)
} else if input.try_parse(|i| i.expect_ident_matching("and")).is_ok() {
Some(QueryCondition::parse_disallow_or(context, input, FeatureType::Media)?)
Some(QueryCondition::parse_disallow_or(context, input)?)
} else {
None
};

View file

@ -7,7 +7,7 @@
//! https://drafts.csswg.org/mediaqueries-4/#typedef-media-condition
//! https://drafts.csswg.org/css-contain-3/#typedef-container-condition
use super::{QueryFeatureExpression, FeatureType};
use super::QueryFeatureExpression;
use crate::parser::ParserContext;
use crate::values::computed;
use cssparser::{Parser, Token};
@ -80,9 +80,8 @@ impl QueryCondition {
pub fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
) -> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, feature_type, AllowOr::Yes)
Self::parse_internal(context, input, AllowOr::Yes)
}
/// Parse a single condition, disallowing `or` expressions.
@ -91,15 +90,13 @@ impl QueryCondition {
pub fn parse_disallow_or<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
) -> Result<Self, ParseError<'i>> {
Self::parse_internal(context, input, feature_type, AllowOr::No)
Self::parse_internal(context, input, AllowOr::No)
}
fn parse_internal<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
allow_or: AllowOr,
) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
@ -112,12 +109,12 @@ impl QueryCondition {
};
if is_negation {
let inner_condition = Self::parse_in_parens(context, input, feature_type)?;
let inner_condition = Self::parse_in_parens(context, input)?;
return Ok(QueryCondition::Not(Box::new(inner_condition)));
}
// ParenthesisBlock.
let first_condition = Self::parse_paren_block(context, input, feature_type)?;
let first_condition = Self::parse_paren_block(context, input)?;
let operator = match input.try_parse(Operator::parse) {
Ok(op) => op,
Err(..) => return Ok(first_condition),
@ -129,7 +126,7 @@ impl QueryCondition {
let mut conditions = vec![];
conditions.push(first_condition);
conditions.push(Self::parse_in_parens(context, input, feature_type)?);
conditions.push(Self::parse_in_parens(context, input)?);
let delim = match operator {
Operator::And => "and",
@ -144,7 +141,7 @@ impl QueryCondition {
));
}
conditions.push(Self::parse_in_parens(context, input, feature_type)?);
conditions.push(Self::parse_in_parens(context, input)?);
}
}
@ -152,23 +149,21 @@ impl QueryCondition {
pub fn parse_in_parens<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
) -> Result<Self, ParseError<'i>> {
input.expect_parenthesis_block()?;
Self::parse_paren_block(context, input, feature_type)
Self::parse_paren_block(context, input)
}
fn parse_paren_block<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
) -> Result<Self, ParseError<'i>> {
input.parse_nested_block(|input| {
// Base case.
if let Ok(inner) = input.try_parse(|i| Self::parse(context, i, feature_type)) {
if let Ok(inner) = input.try_parse(|i| Self::parse(context, i)) {
return Ok(QueryCondition::InParens(Box::new(inner)));
}
let expr = QueryFeatureExpression::parse_in_parenthesis_block(context, input, feature_type)?;
let expr = QueryFeatureExpression::parse_in_parenthesis_block(context, input)?;
Ok(QueryCondition::Feature(expr))
})
}

View file

@ -7,7 +7,11 @@
use super::feature::{Evaluator, QueryFeatureDescription};
use super::feature::{KeywordDiscriminant, ParsingRequirements};
#[cfg(feature = "gecko")]
use crate::gecko::media_features::MEDIA_FEATURES;
use crate::parser::{Parse, ParserContext};
#[cfg(feature = "servo")]
use crate::servo::media_queries::MEDIA_FEATURES;
use crate::str::{starts_with_ignore_ascii_case, string_as_ascii_lowercase};
use crate::values::computed::{self, Ratio, ToComputedValue};
use crate::values::specified::{Integer, Length, Number, Resolution};
@ -18,36 +22,6 @@ use std::cmp::{Ordering, PartialOrd};
use std::fmt::{self, Write};
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
/// Whether we're parsing a media or container query feature.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)]
pub enum FeatureType {
/// We're parsing a media feature.
Media,
/// We're parsing a container feature.
Container,
}
impl FeatureType {
fn features(&self) -> &'static [QueryFeatureDescription] {
#[cfg(feature = "gecko")]
use crate::gecko::media_features::MEDIA_FEATURES;
#[cfg(feature = "servo")]
use crate::servo::media_queries::MEDIA_FEATURES;
use crate::stylesheets::container_rule::CONTAINER_FEATURES;
match *self {
FeatureType::Media => &MEDIA_FEATURES,
FeatureType::Container => &CONTAINER_FEATURES,
}
}
fn find_feature(&self, name: &Atom) -> Option<(usize, &'static QueryFeatureDescription)> {
self.features().iter().enumerate().find(|(_, f)| f.name == *name)
}
}
/// The kind of matching that should be performed on a feature value.
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToShmem)]
pub enum Range {
@ -150,7 +124,6 @@ impl RangeOrOperator {
/// query contained, and the range to evaluate.
#[derive(Clone, Debug, MallocSizeOf, ToShmem, PartialEq)]
pub struct QueryFeatureExpression {
feature_type: FeatureType,
feature_index: usize,
value: Option<QueryExpressionValue>,
range_or_operator: Option<RangeOrOperator>,
@ -271,14 +244,12 @@ fn disabled_by_pref(feature: &Atom, context: &ParserContext) -> bool {
impl QueryFeatureExpression {
fn new(
feature_type: FeatureType,
feature_index: usize,
value: Option<QueryExpressionValue>,
range_or_operator: Option<RangeOrOperator>,
) -> Self {
debug_assert!(feature_index < feature_type.features().len());
debug_assert!(feature_index < MEDIA_FEATURES.len());
Self {
feature_type,
feature_index,
value,
range_or_operator,
@ -286,7 +257,7 @@ impl QueryFeatureExpression {
}
fn feature(&self) -> &'static QueryFeatureDescription {
&self.feature_type.features()[self.feature_index]
&MEDIA_FEATURES[self.feature_index]
}
/// Parse a feature expression of the form:
@ -297,17 +268,15 @@ impl QueryFeatureExpression {
pub fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
) -> Result<Self, ParseError<'i>> {
input.expect_parenthesis_block()?;
input.parse_nested_block(|input| Self::parse_in_parenthesis_block(context, input, feature_type))
input.parse_nested_block(|input| Self::parse_in_parenthesis_block(context, input))
}
/// Parse a feature expression where we've already consumed the parenthesis.
pub fn parse_in_parenthesis_block<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
feature_type: FeatureType,
) -> Result<Self, ParseError<'i>> {
let mut requirements = ParsingRequirements::empty();
let location = input.current_source_location();
@ -336,7 +305,11 @@ impl QueryFeatureExpression {
let atom = Atom::from(string_as_ascii_lowercase(feature_name));
let (feature_index, feature) = match feature_type.find_feature(&atom) {
let (feature_index, feature) = match MEDIA_FEATURES
.iter()
.enumerate()
.find(|(_, f)| f.name == atom)
{
Some((i, f)) => (i, f),
None => {
return Err(location.new_custom_error(
@ -368,7 +341,7 @@ impl QueryFeatureExpression {
);
}
return Ok(Self::new(feature_type, feature_index, None, None));
return Ok(Self::new(feature_index, None, None));
},
Ok(operator) => operator,
};
@ -399,7 +372,7 @@ impl QueryFeatureExpression {
.new_custom_error(StyleParseErrorKind::MediaQueryExpectedFeatureValue)
})?;
Ok(Self::new(feature_type, feature_index, Some(value), range_or_operator))
Ok(Self::new(feature_index, Some(value), range_or_operator))
}
/// Returns whether this query evaluates to true for the given device.

View file

@ -12,7 +12,6 @@ mod condition;
#[macro_use]
pub mod feature;
pub mod feature_expression;
pub mod values;
pub use self::condition::QueryCondition;
pub use self::feature_expression::{QueryFeatureExpression, FeatureType};
pub use self::feature_expression::QueryFeatureExpression;

View file

@ -1,34 +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/. */
//! Common feature values between media and container features.
/// The orientation media / container feature.
#[derive(Clone, Copy, Debug, FromPrimitive, Parse, ToCss)]
#[repr(u8)]
#[allow(missing_docs)]
pub enum Orientation {
Landscape,
Portrait,
}
impl Orientation {
/// A helper to evaluate a orientation query given a generic size getter.
pub fn eval<T>(size: euclid::default::Size2D<T>, value: Option<Self>) -> bool
where
T: PartialOrd,
{
let query_orientation = match value {
Some(v) => v,
None => return true,
};
// Per spec, square viewports should be 'portrait'
let is_landscape = size.width > size.height;
match query_orientation {
Self::Landscape => is_landscape,
Self::Portrait => !is_landscape,
}
}
}

View file

@ -6,20 +6,14 @@
//!
//! [container]: https://drafts.csswg.org/css-contain-3/#container-rule
use crate::logical_geometry::{WritingMode, LogicalSize};
use crate::queries::QueryCondition;
use crate::shared_lock::{
DeepCloneParams, DeepCloneWithLock, Locked, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard,
};
use crate::values::specified::ContainerName;
use crate::values::computed::{Context, CSSPixelLength, Ratio};
use crate::str::CssStringWriter;
use crate::stylesheets::CssRules;
use crate::queries::feature::{AllowsRanges, Evaluator, ParsingRequirements, QueryFeatureDescription};
use crate::queries::values::Orientation;
use app_units::Au;
use cssparser::SourceLocation;
use euclid::default::Size2D;
#[cfg(feature = "gecko")]
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
use servo_arc::Arc;
@ -83,79 +77,3 @@ impl ToCssWithGuard for ContainerRule {
/// TODO: Factor out the media query code to work with containers.
pub type ContainerCondition = QueryCondition;
fn get_container(_context: &Context) -> (Size2D<Au>, WritingMode) {
unimplemented!("TODO: implement container matching");
}
fn eval_width(context: &Context) -> CSSPixelLength {
let (size, _wm) = get_container(context);
CSSPixelLength::new(size.width.to_f32_px())
}
fn eval_height(context: &Context) -> CSSPixelLength {
let (size, _wm) = get_container(context);
CSSPixelLength::new(size.height.to_f32_px())
}
fn eval_inline_size(context: &Context) -> CSSPixelLength {
let (size, wm) = get_container(context);
CSSPixelLength::new(LogicalSize::from_physical(wm, size).inline.to_f32_px())
}
fn eval_block_size(context: &Context) -> CSSPixelLength {
let (size, wm) = get_container(context);
CSSPixelLength::new(LogicalSize::from_physical(wm, size).block.to_f32_px())
}
fn eval_aspect_ratio(context: &Context) -> Ratio {
let (size, _wm) = get_container(context);
Ratio::new(size.width.0 as f32, size.height.0 as f32)
}
fn eval_orientation(context: &Context, value: Option<Orientation>) -> bool {
let (size, _wm) = get_container(context);
Orientation::eval(size, value)
}
/// https://drafts.csswg.org/css-contain-3/#container-features
///
/// TODO: Support style queries, perhaps.
pub static CONTAINER_FEATURES: [QueryFeatureDescription; 6] = [
feature!(
atom!("width"),
AllowsRanges::Yes,
Evaluator::Length(eval_width),
ParsingRequirements::empty(),
),
feature!(
atom!("height"),
AllowsRanges::Yes,
Evaluator::Length(eval_height),
ParsingRequirements::empty(),
),
feature!(
atom!("inline-size"),
AllowsRanges::Yes,
Evaluator::Length(eval_inline_size),
ParsingRequirements::empty(),
),
feature!(
atom!("block-size"),
AllowsRanges::Yes,
Evaluator::Length(eval_block_size),
ParsingRequirements::empty(),
),
feature!(
atom!("aspect-ratio"),
AllowsRanges::Yes,
Evaluator::NumberRatio(eval_aspect_ratio),
ParsingRequirements::empty(),
),
feature!(
atom!("orientation"),
AllowsRanges::No,
keyword_evaluator!(eval_orientation, Orientation),
ParsingRequirements::empty(),
),
];

View file

@ -10,7 +10,6 @@ use crate::font_face::parse_font_face_block;
use crate::media_queries::MediaList;
use crate::parser::{Parse, ParserContext};
use crate::properties::parse_property_declaration_list;
use crate::queries::FeatureType;
use crate::selector_parser::{SelectorImpl, SelectorParser};
use crate::shared_lock::{Locked, SharedRwLock};
use crate::str::starts_with_ignore_ascii_case;
@ -439,7 +438,7 @@ impl<'a, 'b, 'i> AtRuleParser<'i> for NestedRuleParser<'a, 'b> {
let name = input.try_parse(|input| {
ContainerName::parse(self.context, input)
}).ok().unwrap_or_else(ContainerName::none);
let condition = ContainerCondition::parse(self.context, input, FeatureType::Container)?;
let condition = ContainerCondition::parse(self.context, input)?;
AtRulePrelude::Container(name, condition)
},
"layer" if static_prefs::pref!("layout.css.cascade-layers.enabled") => {

View file

@ -8,7 +8,7 @@
use crate::gecko_bindings::sugar::ownership::{HasBoxFFI, HasFFI, HasSimpleFFI};
use crate::media_queries::Device;
use crate::parser::{Parse, ParserContext};
use crate::queries::{QueryCondition, FeatureType};
use crate::queries::QueryCondition;
use crate::values::computed::{self, ToComputedValue};
use crate::values::specified::{Length, NoCalcLength, ViewportPercentageLength};
use app_units::Au;
@ -30,7 +30,7 @@ impl Parse for SourceSize {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let condition = QueryCondition::parse(context, input, FeatureType::Media)?;
let condition = QueryCondition::parse(context, input)?;
let value = Length::parse_non_negative(context, input)?;
Ok(Self { condition, value })
}

View file

@ -1,4 +1,22 @@
[at-container-parsing.html]
[(inline-size)]
expected: FAIL
[(min-inline-size: 0px)]
expected: FAIL
[(max-inline-size: 0px)]
expected: FAIL
[(block-size)]
expected: FAIL
[(min-block-size: 0px)]
expected: FAIL
[(max-block-size: 0px)]
expected: FAIL
[(100px < width)]
expected: FAIL

View file

@ -2,5 +2,11 @@
[Serialization of conditionText]
expected: FAIL
[Serialization of inner @container rule]
expected: FAIL
[Serialization of nested @container rule]
expected: FAIL
[Serialization of range condition syntax]
expected: FAIL

View file

@ -1,4 +1,13 @@
[container-selection.html]
[a (inline-size: 8px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
[b (inline-size: 16px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
[a (block-size: 32px) for .a-size > .b-size > .a-inline > span]
expected: FAIL
[(height: 16px) for .size > .inline > span]
expected: FAIL

View file

@ -0,0 +1,6 @@
[idlharness.html]
[Stringification of sheet.cssRules[0\].cssRules[0\]]
expected: FAIL
[CSSContainerRule must be primary interface of sheet.cssRules[0\].cssRules[0\]]
expected: FAIL

View file

@ -1,4 +1,40 @@
[size-feature-evaluation.html]
[(inline-size >= 100px) (.horizontal)]
expected: FAIL
[(min-inline-size: 100px) (.horizontal)]
expected: FAIL
[(max-inline-size: 100px) (.horizontal)]
expected: FAIL
[(block-size >= 200px) (.horizontal)]
expected: FAIL
[(min-block-size: 200px) (.horizontal)]
expected: FAIL
[(max-block-size: 200px) (.horizontal)]
expected: FAIL
[(block-size >= 100px) (.vertical)]
expected: FAIL
[(min-block-size: 100px) (.vertical)]
expected: FAIL
[(max-block-size: 100px) (.vertical)]
expected: FAIL
[(inline-size >= 200px) (.vertical)]
expected: FAIL
[(min-inline-size: 200px) (.vertical)]
expected: FAIL
[(max-inline-size: 200px) (.vertical)]
expected: FAIL
[(width < 100px) (.horizontal)]
expected: FAIL
@ -46,39 +82,3 @@
[(aspect-ratio: 2/1) (.vertical)]
expected: FAIL
[(inline-size < 100px) (.horizontal)]
expected: FAIL
[(min-inline-size: 101px) (.horizontal)]
expected: FAIL
[(max-inline-size: 99px) (.horizontal)]
expected: FAIL
[(block-size < 200px) (.horizontal)]
expected: FAIL
[(min-block-size: 201px) (.horizontal)]
expected: FAIL
[(max-block-size: 199px) (.horizontal)]
expected: FAIL
[(block-size < 100px) (.vertical)]
expected: FAIL
[(min-block-size: 101px) (.vertical)]
expected: FAIL
[(max-block-size: 99px) (.vertical)]
expected: FAIL
[(inline-size < 200px) (.vertical)]
expected: FAIL
[(min-inline-size: 201px) (.vertical)]
expected: FAIL
[(max-inline-size: 199px) (.vertical)]
expected: FAIL

View file

@ -1,4 +1,7 @@
[unsupported-axis.html]
[(inline-size > 0px)]
expected: FAIL
[(height > 0px)]
expected: FAIL
@ -19,9 +22,3 @@
[((height > 0px) or (orientation: landscape)), with contain:size]
expected: FAIL
[(block-size > 0px)]
expected: FAIL
[(block-size > 0px), with writing-mode:vertical-rl]
expected: FAIL

View file

@ -183,7 +183,6 @@ STATIC_ATOMS = [
Atom("bindToUntrustedContent", "bindToUntrustedContent"),
Atom("black", "black"),
Atom("block", "block"),
Atom("block_size", "block-size"),
Atom("blockquote", "blockquote"),
Atom("blur", "blur"),
Atom("body", "body"),
@ -2316,7 +2315,6 @@ STATIC_ATOMS = [
Atom("heading", "heading"),
Atom("hitregion", "hitregion"),
Atom("inlinevalue", "inline"),
Atom("inline_size", "inline-size"),
Atom("invalid", "invalid"),
Atom("lineNumber", "line-number"),
Atom("menuitemcheckbox", "menuitemcheckbox"),