From 5af0d7ca7c4f881460e4ac1ad9dac525e29c94e7 Mon Sep 17 00:00:00 2001 From: Philipp Zech Date: Wed, 17 Jun 2020 11:08:44 +0000 Subject: [PATCH 01/17] style: Remove StyleFontSize enum from nsStyleConsts.h. Differential Revision: https://phabricator.services.mozilla.com/D77511 --- components/style/properties/cascade.rs | 7 +- components/style/properties/gecko.mako.rs | 52 +++------------ .../style/properties/longhands/font.mako.rs | 3 +- components/style/values/computed/font.rs | 6 +- components/style/values/specified/font.rs | 65 +++++++++++-------- components/style/values/specified/mod.rs | 2 +- 6 files changed, 56 insertions(+), 79 deletions(-) diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index ab60099b3a4..595534bd974 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -854,12 +854,13 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { let new_size = { let font = self.context.builder.get_font(); - let new_size = match font.clone_font_size().keyword_info { - Some(info) => { + let info = font.clone_font_size().keyword_info; + let new_size = match info.kw { + specified::FontSizeKeyword::None => return, + _ => { self.context.for_non_inherited_property = None; specified::FontSize::Keyword(info).to_computed_value(self.context) } - None => return, }; if font.gecko().mScriptUnconstrainedSize == Au::from(new_size.size()).0 { diff --git a/components/style/properties/gecko.mako.rs b/components/style/properties/gecko.mako.rs index 69d0ac3fb92..a8e246b4a0e 100644 --- a/components/style/properties/gecko.mako.rs +++ b/components/style/properties/gecko.mako.rs @@ -942,62 +942,26 @@ fn static_assert() { } pub fn set_font_size(&mut self, v: FontSize) { - use crate::values::specified::font::KeywordSize; - let size = Au::from(v.size()); self.gecko.mScriptUnconstrainedSize = size.0; // These two may be changed from Cascade::fixup_font_stuff. self.gecko.mSize = size.0; self.gecko.mFont.size = size.0; - - if let Some(info) = v.keyword_info { - self.gecko.mFontSizeKeyword = match info.kw { - KeywordSize::XXSmall => structs::StyleFontSize::Xxsmall, - KeywordSize::XSmall => structs::StyleFontSize::Xsmall, - KeywordSize::Small => structs::StyleFontSize::Small, - KeywordSize::Medium => structs::StyleFontSize::Medium, - KeywordSize::Large => structs::StyleFontSize::Large, - KeywordSize::XLarge => structs::StyleFontSize::Xxlarge, - KeywordSize::XXLarge => structs::StyleFontSize::Xxlarge, - KeywordSize::XXXLarge => structs::StyleFontSize::Xxxlarge, - }; - self.gecko.mFontSizeFactor = info.factor; - self.gecko.mFontSizeOffset = info.offset.to_i32_au(); - } else { - self.gecko.mFontSizeKeyword = structs::StyleFontSize::NoKeyword; - self.gecko.mFontSizeFactor = 1.; - self.gecko.mFontSizeOffset = 0; - } + self.gecko.mFontSizeKeyword = v.keyword_info.kw; + self.gecko.mFontSizeFactor = v.keyword_info.factor; + self.gecko.mFontSizeOffset = v.keyword_info.offset.to_i32_au(); } pub fn clone_font_size(&self) -> FontSize { - use crate::values::specified::font::{KeywordInfo, KeywordSize}; - let size = Au(self.gecko.mSize).into(); - let kw = match self.gecko.mFontSizeKeyword { - structs::StyleFontSize::Xxsmall => KeywordSize::XXSmall, - structs::StyleFontSize::Xsmall => KeywordSize::XSmall, - structs::StyleFontSize::Small => KeywordSize::Small, - structs::StyleFontSize::Medium => KeywordSize::Medium, - structs::StyleFontSize::Large => KeywordSize::Large, - structs::StyleFontSize::Xlarge => KeywordSize::XLarge, - structs::StyleFontSize::Xxlarge => KeywordSize::XXLarge, - structs::StyleFontSize::Xxxlarge => KeywordSize::XXXLarge, - structs::StyleFontSize::NoKeyword => { - return FontSize { - size, - keyword_info: None, - } - } - _ => unreachable!("mFontSizeKeyword should be an absolute keyword or NO_KEYWORD") - }; + use crate::values::specified::font::KeywordInfo; FontSize { - size, - keyword_info: Some(KeywordInfo { - kw, + size: Au(self.gecko.mSize).into(), + keyword_info: KeywordInfo { + kw: self.gecko.mFontSizeKeyword, factor: self.gecko.mFontSizeFactor, offset: Au(self.gecko.mFontSizeOffset).into() - }) + } } } diff --git a/components/style/properties/longhands/font.mako.rs b/components/style/properties/longhands/font.mako.rs index 98ed7fb7f9e..17836902740 100644 --- a/components/style/properties/longhands/font.mako.rs +++ b/components/style/properties/longhands/font.mako.rs @@ -362,6 +362,7 @@ ${helpers.predefined_type( use crate::gecko_bindings::structs::{LookAndFeel_FontID, nsFont}; use std::mem; use crate::values::computed::Percentage; + use crate::values::specified::font::KeywordInfo; use crate::values::computed::font::{FontFamily, FontSize, FontStretch, FontStyle, FontFamilyList}; use crate::values::generics::NonNegative; @@ -397,7 +398,7 @@ ${helpers.predefined_type( }, font_size: FontSize { size: NonNegative(cx.maybe_zoom_text(Au(system.size).into())), - keyword_info: None + keyword_info: KeywordInfo::none() }, font_weight, font_stretch, diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 25a93d68348..57ca8e97a86 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -101,7 +101,7 @@ pub struct FontSize { pub size: NonNegativeLength, /// If derived from a keyword, the keyword and additional transformations applied to it #[css(skip)] - pub keyword_info: Option, + pub keyword_info: KeywordInfo, } impl FontWeight { @@ -170,7 +170,7 @@ impl FontSize { pub fn medium() -> Self { Self { size: NonNegative(Length::new(specified::FONT_MEDIUM_PX as CSSFloat)), - keyword_info: Some(KeywordInfo::medium()), + keyword_info: KeywordInfo::medium(), } } } @@ -187,7 +187,7 @@ impl ToAnimatedValue for FontSize { fn from_animated_value(animated: Self::AnimatedValue) -> Self { FontSize { size: NonNegative(animated.clamp_to_non_negative()), - keyword_info: None, + keyword_info: KeywordInfo::none(), } } } diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 1a77a3864ef..39233dfc572 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -511,9 +511,11 @@ pub enum KeywordSize { XXLarge, #[css(keyword = "xxx-large")] XXXLarge, + #[css(skip)] + None, } -impl KeywordSize { +impl FontSizeKeyword { /// Convert to an HTML value #[inline] pub fn html_size(self) -> u8 { @@ -521,9 +523,9 @@ impl KeywordSize { } } -impl Default for KeywordSize { +impl Default for FontSizeKeyword { fn default() -> Self { - KeywordSize::Medium + FontSizeKeyword::Medium } } @@ -546,7 +548,7 @@ impl Default for KeywordSize { /// Additional information for keyword-derived font sizes. pub struct KeywordInfo { /// The keyword used - pub kw: KeywordSize, + pub kw: FontSizeKeyword, /// A factor to be multiplied by the computed size of the keyword #[css(skip)] pub factor: f32, @@ -559,10 +561,15 @@ pub struct KeywordInfo { impl KeywordInfo { /// KeywordInfo value for font-size: medium pub fn medium() -> Self { - Self::new(KeywordSize::Medium) + Self::new(FontSizeKeyword::Medium) } - fn new(kw: KeywordSize) -> Self { + /// KeywordInfo value for font-size: none + pub fn none() -> Self { + Self::new(FontSizeKeyword::None) + } + + fn new(kw: FontSizeKeyword) -> Self { KeywordInfo { kw, factor: 1., @@ -573,6 +580,7 @@ impl KeywordInfo { /// Computes the final size for this font-size keyword, accounting for /// text-zoom. fn to_computed_value(&self, context: &Context) -> CSSPixelLength { + debug_assert_ne!(self.kw, FontSizeKeyword::None); let base = context.maybe_zoom_text(self.kw.to_length(context).0); base * self.factor + context.maybe_zoom_text(self.offset) } @@ -580,6 +588,9 @@ impl KeywordInfo { /// Given a parent keyword info (self), apply an additional factor/offset to /// it. fn compose(self, factor: f32) -> Self { + if self.kw == FontSizeKeyword::None { + return self; + } KeywordInfo { kw: self.kw, factor: self.factor * factor, @@ -590,7 +601,7 @@ impl KeywordInfo { impl SpecifiedValueInfo for KeywordInfo { fn collect_completion_keywords(f: KeywordsCollectFn) { - ::collect_completion_keywords(f); + ::collect_completion_keywords(f); } } @@ -766,21 +777,21 @@ const LARGER_FONT_SIZE_RATIO: f32 = 1.2; /// The default font size. pub const FONT_MEDIUM_PX: i32 = 16; -impl KeywordSize { +impl FontSizeKeyword { #[inline] #[cfg(feature = "servo")] fn to_length(&self, _: &Context) -> NonNegativeLength { let medium = Length::new(FONT_MEDIUM_PX as f32); // https://drafts.csswg.org/css-fonts-3/#font-size-prop NonNegative(match *self { - KeywordSize::XXSmall => medium * 3.0 / 5.0, - KeywordSize::XSmall => medium * 3.0 / 4.0, - KeywordSize::Small => medium * 8.0 / 9.0, - KeywordSize::Medium => medium, - KeywordSize::Large => medium * 6.0 / 5.0, - KeywordSize::XLarge => medium * 3.0 / 2.0, - KeywordSize::XXLarge => medium * 2.0, - KeywordSize::XXXLarge => medium * 3.0, + FontSizeKeyword::XXSmall => medium * 3.0 / 5.0, + FontSizeKeyword::XSmall => medium * 3.0 / 4.0, + FontSizeKeyword::Small => medium * 8.0 / 9.0, + FontSizeKeyword::Medium => medium, + FontSizeKeyword::Large => medium * 6.0 / 5.0, + FontSizeKeyword::XLarge => medium * 3.0 / 2.0, + FontSizeKeyword::XXLarge => medium * 2.0, + FontSizeKeyword::XXXLarge => medium * 3.0, }) } @@ -861,14 +872,14 @@ impl FontSize { pub fn from_html_size(size: u8) -> Self { FontSize::Keyword(KeywordInfo::new(match size { // If value is less than 1, let it be 1. - 0 | 1 => KeywordSize::XSmall, - 2 => KeywordSize::Small, - 3 => KeywordSize::Medium, - 4 => KeywordSize::Large, - 5 => KeywordSize::XLarge, - 6 => KeywordSize::XXLarge, + 0 | 1 => FontSizeKeyword::XSmall, + 2 => FontSizeKeyword::Small, + 3 => FontSizeKeyword::Medium, + 4 => FontSizeKeyword::Large, + 5 => FontSizeKeyword::XLarge, + 6 => FontSizeKeyword::XXLarge, // If value is greater than 7, let it be 7. - _ => KeywordSize::XXXLarge, + _ => FontSizeKeyword::XXXLarge, })) } @@ -886,9 +897,9 @@ impl FontSize { .get_parent_font() .clone_font_size() .keyword_info - .map(|i| i.compose(factor)) + .compose(factor) }; - let mut info = None; + let mut info = KeywordInfo::none(); let size = match *self { FontSize::Length(LengthPercentage::Length(NoCalcLength::FontRelative(value))) => { if let FontRelativeLength::Em(em) = value { @@ -917,7 +928,7 @@ impl FontSize { }, FontSize::Keyword(i) => { // As a specified keyword, this is keyword derived - info = Some(i); + info = i; i.to_computed_value(context).clamp_to_non_negative() }, FontSize::Smaller => { @@ -991,7 +1002,7 @@ impl FontSize { return Ok(FontSize::Length(lp)); } - if let Ok(kw) = input.try(KeywordSize::parse) { + if let Ok(kw) = input.try(FontSizeKeyword::parse) { return Ok(FontSize::Keyword(KeywordInfo::new(kw))); } diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 4bb910fc97d..9d90ffab1b0 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -50,7 +50,7 @@ pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; pub use self::font::{FontFamily, FontLanguageOverride, FontStyle}; pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric}; -pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis}; +pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontSizeKeyword}; pub use self::font::{FontVariantAlternates, FontWeight}; pub use self::font::{FontVariantEastAsian, FontVariationSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; From 685e749cfc5f848202da0ad755161bb596b8548a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 17 Jun 2020 22:27:37 +0000 Subject: [PATCH 02/17] style: Switch all callsites of try() to try_parse() in the style crate. Fully automated via: $ rg -l '\.try\(' | xargs sed -i 's/\.try(/.try_parse(/g' $ cd servo/components/style && cargo +nightly fmt Differential Revision: https://phabricator.services.mozilla.com/D80099 --- components/style/counter_style/mod.rs | 16 +-- components/style/custom_properties.rs | 4 +- components/style/font_face.rs | 8 +- .../style/media_queries/media_condition.rs | 6 +- .../media_queries/media_feature_expression.rs | 6 +- components/style/media_queries/media_query.rs | 6 +- .../style/properties/declaration_block.rs | 2 +- components/style/properties/helpers.mako.rs | 4 +- .../style/properties/properties.mako.rs | 8 +- .../properties/shorthands/background.mako.rs | 8 +- .../properties/shorthands/border.mako.rs | 20 +-- .../style/properties/shorthands/box.mako.rs | 14 +- .../properties/shorthands/column.mako.rs | 8 +- .../style/properties/shorthands/font.mako.rs | 24 ++-- .../shorthands/inherited_text.mako.rs | 8 +- .../style/properties/shorthands/list.mako.rs | 8 +- .../properties/shorthands/outline.mako.rs | 6 +- .../properties/shorthands/position.mako.rs | 60 ++++----- .../style/properties/shorthands/svg.mako.rs | 8 +- .../style/properties/shorthands/text.mako.rs | 2 +- components/style/stylesheets/document_rule.rs | 2 +- components/style/stylesheets/rule_parser.rs | 2 +- components/style/stylesheets/supports_rule.rs | 16 +-- components/style/stylesheets/viewport_rule.rs | 6 +- components/style/values/computed/font.rs | 4 +- components/style/values/generics/font.rs | 5 +- components/style/values/generics/grid.rs | 16 +-- components/style/values/generics/length.rs | 2 +- components/style/values/generics/mod.rs | 4 +- components/style/values/generics/rect.rs | 6 +- components/style/values/generics/size.rs | 2 +- components/style/values/generics/svg.rs | 2 +- components/style/values/generics/text.rs | 5 +- components/style/values/specified/align.rs | 33 ++--- .../style/values/specified/background.rs | 7 +- .../style/values/specified/basic_shape.rs | 29 ++-- components/style/values/specified/border.rs | 11 +- components/style/values/specified/box.rs | 41 +++--- components/style/values/specified/color.rs | 6 +- components/style/values/specified/counters.rs | 14 +- components/style/values/specified/easing.rs | 6 +- components/style/values/specified/effects.rs | 34 ++--- components/style/values/specified/font.rs | 44 +++--- components/style/values/specified/grid.rs | 37 +++--- components/style/values/specified/image.rs | 125 ++++++++++-------- components/style/values/specified/length.rs | 8 +- components/style/values/specified/list.rs | 8 +- components/style/values/specified/mod.rs | 16 ++- components/style/values/specified/motion.rs | 16 ++- components/style/values/specified/outline.rs | 2 +- components/style/values/specified/position.rs | 48 ++++--- .../values/specified/source_size_list.rs | 2 +- components/style/values/specified/svg.rs | 9 +- components/style/values/specified/text.rs | 25 ++-- .../style/values/specified/transform.rs | 47 ++++--- components/style/values/specified/ui.rs | 6 +- 56 files changed, 469 insertions(+), 403 deletions(-) diff --git a/components/style/counter_style/mod.rs b/components/style/counter_style/mod.rs index 9c4be49bb91..ecdc8828ec1 100644 --- a/components/style/counter_style/mod.rs +++ b/components/style/counter_style/mod.rs @@ -369,7 +369,7 @@ impl Parse for System { "symbolic" => Ok(System::Symbolic), "additive" => Ok(System::Additive), "fixed" => { - let first_symbol_value = input.try(|i| Integer::parse(context, i)).ok(); + let first_symbol_value = input.try_parse(|i| Integer::parse(context, i)).ok(); Ok(System::Fixed { first_symbol_value }) }, "extends" => { @@ -458,7 +458,7 @@ impl Parse for Negative { ) -> Result> { Ok(Negative( Symbol::parse(context, input)?, - input.try(|input| Symbol::parse(context, input)).ok(), + input.try_parse(|input| Symbol::parse(context, input)).ok(), )) } } @@ -494,7 +494,7 @@ impl Parse for CounterRanges { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("auto")) + .try_parse(|input| input.expect_ident_matching("auto")) .is_ok() { return Ok(CounterRanges(Default::default())); @@ -519,7 +519,7 @@ fn parse_bound<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(integer) = input.try(|input| Integer::parse(context, input)) { + if let Ok(integer) = input.try_parse(|input| Integer::parse(context, input)) { return Ok(CounterBound::Integer(integer)); } input.expect_ident_matching("infinite")?; @@ -535,7 +535,7 @@ impl Parse for Pad { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let pad_with = input.try(|input| Symbol::parse(context, input)); + let pad_with = input.try_parse(|input| Symbol::parse(context, input)); let min_length = Integer::parse_non_negative(context, input)?; let pad_with = pad_with.or_else(|_| Symbol::parse(context, input))?; Ok(Pad(min_length, pad_with)) @@ -568,7 +568,7 @@ impl Parse for Symbols { input: &mut Parser<'i, 't>, ) -> Result> { let mut symbols = Vec::new(); - while let Ok(s) = input.try(|input| Symbol::parse(context, input)) { + while let Ok(s) = input.try_parse(|input| Symbol::parse(context, input)) { symbols.push(s); } if symbols.is_empty() { @@ -618,7 +618,7 @@ impl Parse for AdditiveTuple { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let symbol = input.try(|input| Symbol::parse(context, input)); + let symbol = input.try_parse(|input| Symbol::parse(context, input)); let weight = Integer::parse_non_negative(context, input)?; let symbol = symbol.or_else(|_| Symbol::parse(context, input))?; Ok(Self { weight, symbol }) @@ -648,7 +648,7 @@ impl Parse for SpeakAs { input: &mut Parser<'i, 't>, ) -> Result> { let mut is_spell_out = false; - let result = input.try(|input| { + let result = input.try_parse(|input| { let ident = input.expect_ident().map_err(|_| ())?; match_ignore_ascii_case! { &*ident, "auto" => Ok(SpeakAs::Auto), diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index d0af57886db..23e25b5a155 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -489,7 +489,7 @@ fn parse_var_function<'i, 't>( let name = parse_name(&name).map_err(|()| { input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(name.clone())) })?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { parse_fallback(input)?; } if let Some(refs) = references { @@ -505,7 +505,7 @@ fn parse_env_function<'i, 't>( // TODO(emilio): This should be per spec, but no other // browser does that, see https://github.com/w3c/csswg-drafts/issues/3262. input.expect_ident()?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { parse_fallback(input)?; } if let Some(references) = references { diff --git a/components/style/font_face.rs b/components/style/font_face.rs index 21e2946d6a6..3ddd6b69a85 100644 --- a/components/style/font_face.rs +++ b/components/style/font_face.rs @@ -122,7 +122,7 @@ macro_rules! impl_range { ) -> Result> { let first = $component::parse(context, input)?; let second = input - .try(|input| $component::parse(context, input)) + .try_parse(|input| $component::parse(context, input)) .unwrap_or_else(|_| first.clone()); Ok($range(first, second)) } @@ -236,7 +236,7 @@ impl Parse for FontStyle { GenericFontStyle::Italic => FontStyle::Italic, GenericFontStyle::Oblique(angle) => { let second_angle = input - .try(|input| SpecifiedFontStyle::parse_angle(context, input)) + .try_parse(|input| SpecifiedFontStyle::parse_angle(context, input)) .unwrap_or_else(|_| angle.clone()); FontStyle::Oblique(angle, second_angle) @@ -383,7 +383,7 @@ impl Parse for Source { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_function_matching("local")) + .try_parse(|input| input.expect_function_matching("local")) .is_ok() { return input @@ -395,7 +395,7 @@ impl Parse for Source { // Parsing optional format() let format_hints = if input - .try(|input| input.expect_function_matching("format")) + .try_parse(|input| input.expect_function_matching("format")) .is_ok() { input.parse_nested_block(|input| { diff --git a/components/style/media_queries/media_condition.rs b/components/style/media_queries/media_condition.rs index 19e20105819..f735704556e 100644 --- a/components/style/media_queries/media_condition.rs +++ b/components/style/media_queries/media_condition.rs @@ -114,7 +114,7 @@ impl MediaCondition { // ParenthesisBlock. let first_condition = Self::parse_paren_block(context, input)?; - let operator = match input.try(Operator::parse) { + let operator = match input.try_parse(Operator::parse) { Ok(op) => op, Err(..) => return Ok(first_condition), }; @@ -133,7 +133,7 @@ impl MediaCondition { }; loop { - if input.try(|i| i.expect_ident_matching(delim)).is_err() { + if input.try_parse(|i| i.expect_ident_matching(delim)).is_err() { return Ok(MediaCondition::Operation( conditions.into_boxed_slice(), operator, @@ -159,7 +159,7 @@ impl MediaCondition { ) -> Result> { input.parse_nested_block(|input| { // Base case. - if let Ok(inner) = input.try(|i| Self::parse(context, i)) { + if let Ok(inner) = input.try_parse(|i| Self::parse(context, i)) { return Ok(MediaCondition::InParens(Box::new(inner))); } let expr = MediaFeatureExpression::parse_in_parenthesis_block(context, input)?; diff --git a/components/style/media_queries/media_feature_expression.rs b/components/style/media_queries/media_feature_expression.rs index 9e2fdd2d47b..61e62f4ab70 100644 --- a/components/style/media_queries/media_feature_expression.rs +++ b/components/style/media_queries/media_feature_expression.rs @@ -200,14 +200,14 @@ fn consume_operation_or_colon(input: &mut Parser) -> Result, () Ok(Some(match first_delim { '=' => Operator::Equal, '>' => { - if input.try(|i| i.expect_delim('=')).is_ok() { + if input.try_parse(|i| i.expect_delim('=')).is_ok() { Operator::GreaterThanEqual } else { Operator::GreaterThan } }, '<' => { - if input.try(|i| i.expect_delim('=')).is_ok() { + if input.try_parse(|i| i.expect_delim('=')).is_ok() { Operator::LessThanEqual } else { Operator::LessThan @@ -314,7 +314,7 @@ impl MediaFeatureExpression { )); } - let operator = input.try(consume_operation_or_colon); + let operator = input.try_parse(consume_operation_or_colon); let operator = match operator { Err(..) => { // If there's no colon, this is a media query of the diff --git a/components/style/media_queries/media_query.rs b/components/style/media_queries/media_query.rs index 1768053dbce..83e34c5037f 100644 --- a/components/style/media_queries/media_query.rs +++ b/components/style/media_queries/media_query.rs @@ -125,8 +125,8 @@ impl MediaQuery { input: &mut Parser<'i, 't>, ) -> Result> { let (qualifier, explicit_media_type) = input - .try(|input| -> Result<_, ()> { - let qualifier = input.try(Qualifier::parse).ok(); + .try_parse(|input| -> Result<_, ()> { + let qualifier = input.try_parse(Qualifier::parse).ok(); let ident = input.expect_ident().map_err(|_| ())?; let media_type = MediaQueryType::parse(&ident)?; Ok((qualifier, Some(media_type))) @@ -135,7 +135,7 @@ impl MediaQuery { let condition = if explicit_media_type.is_none() { Some(MediaCondition::parse(context, input)?) - } else if input.try(|i| i.expect_ident_matching("and")).is_ok() { + } else if input.try_parse(|i| i.expect_ident_matching("and")).is_ok() { Some(MediaCondition::parse_disallow_or(context, input)?) } else { None diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index cc2cb20a3c6..5dc5d207f36 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -1357,7 +1357,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> { input.parse_until_before(Delimiter::Bang, |input| { PropertyDeclaration::parse_into(self.declarations, id, self.context, input) })?; - let importance = match input.try(parse_important) { + let importance = match input.try_parse(parse_important) { Ok(()) => Importance::Important, Err(_) => Importance::Normal, }; diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index 9baab22cb45..505cd0c0856 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -354,7 +354,7 @@ use style_traits::Separator; % if allow_empty: - if input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { return Ok(SpecifiedValue(Default::default())) } % endif @@ -994,7 +994,7 @@ let first = parse_one(context, input)?; let second = - input.try(|input| parse_one(context, input)).unwrap_or_else(|_| first.clone()); + input.try_parse(|input| parse_one(context, input)).unwrap_or_else(|_| first.clone()); Ok(expanded! { ${to_rust_ident(first_property)}: first, ${to_rust_ident(second_property)}: second, diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index b9cd617027b..12904fe1ca4 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1655,7 +1655,7 @@ impl UnparsedValue { let mut input = ParserInput::new(&css); let mut input = Parser::new(&mut input); input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - if let Ok(keyword) = input.try(CSSWideKeyword::parse) { + if let Ok(keyword) = input.try_parse(CSSWideKeyword::parse) { return PropertyDeclaration::css_wide_keyword(longhand_id, keyword); } @@ -2380,7 +2380,7 @@ impl PropertyDeclaration { // FIXME: fully implement https://github.com/w3c/csswg-drafts/issues/774 // before adding skip_whitespace here. // This probably affects some test results. - let value = match input.try(CSSWideKeyword::parse) { + let value = match input.try_parse(CSSWideKeyword::parse) { Ok(keyword) => CustomDeclarationValue::CSSWideKeyword(keyword), Err(()) => CustomDeclarationValue::Value( crate::custom_properties::SpecifiedValue::parse(input)? @@ -2395,7 +2395,7 @@ impl PropertyDeclaration { PropertyId::LonghandAlias(id, _) | PropertyId::Longhand(id) => { input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - input.try(CSSWideKeyword::parse).map(|keyword| { + input.try_parse(CSSWideKeyword::parse).map(|keyword| { PropertyDeclaration::css_wide_keyword(id, keyword) }).or_else(|()| { input.look_for_var_or_env_functions(); @@ -2425,7 +2425,7 @@ impl PropertyDeclaration { PropertyId::ShorthandAlias(id, _) | PropertyId::Shorthand(id) => { input.skip_whitespace(); // Unnecessary for correctness, but may help try() rewind less. - if let Ok(keyword) = input.try(CSSWideKeyword::parse) { + if let Ok(keyword) = input.try_parse(CSSWideKeyword::parse) { if id == ShorthandId::All { declarations.all_shorthand = AllShorthand::CSSWideKeyword(keyword) } else { diff --git a/components/style/properties/shorthands/background.mako.rs b/components/style/properties/shorthands/background.mako.rs index ba9391cb8e8..dc28b6f6076 100644 --- a/components/style/properties/shorthands/background.mako.rs +++ b/components/style/properties/shorthands/background.mako.rs @@ -59,19 +59,19 @@ % endfor loop { if background_color.is_none() { - if let Ok(value) = input.try(|i| Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| Color::parse(context, i)) { background_color = Some(value); continue } } if position.is_none() { - if let Ok(value) = input.try(|input| { + if let Ok(value) = input.try_parse(|input| { Position::parse_three_value_quirky(context, input, AllowQuirks::No) }) { position = Some(value); // Parse background size, if applicable. - size = input.try(|input| { + size = input.try_parse(|input| { input.expect_delim('/')?; background_size::single_value::parse(context, input) }).ok(); @@ -81,7 +81,7 @@ } % for name in "image repeat attachment origin clip".split(): if ${name}.is_none() { - if let Ok(value) = input.try(|input| background_${name}::single_value + if let Ok(value) = input.try_parse(|input| background_${name}::single_value ::parse(context, input)) { ${name} = Some(value); continue diff --git a/components/style/properties/shorthands/border.mako.rs b/components/style/properties/shorthands/border.mako.rs index e5122153db7..7419ad90217 100644 --- a/components/style/properties/shorthands/border.mako.rs +++ b/components/style/properties/shorthands/border.mako.rs @@ -71,20 +71,20 @@ pub fn parse_border<'i, 't>( let mut any = false; loop { if width.is_none() { - if let Ok(value) = input.try(|i| BorderSideWidth::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| BorderSideWidth::parse(context, i)) { width = Some(value); any = true; } } if style.is_none() { - if let Ok(value) = input.try(BorderStyle::parse) { + if let Ok(value) = input.try_parse(BorderStyle::parse) { style = Some(value); any = true; continue } } if color.is_none() { - if let Ok(value) = input.try(|i| Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| Color::parse(context, i)) { color = Some(value); any = true; continue @@ -301,24 +301,24 @@ pub fn parse_border<'i, 't>( let mut border_image_${name} = border_image_${name}::get_initial_specified_value(); % endfor - let result: Result<_, ParseError> = input.try(|input| { + let result: Result<_, ParseError> = input.try_parse(|input| { % for name in "outset repeat slice source width".split(): let mut ${name} = None; % endfor loop { if slice.is_none() { - if let Ok(value) = input.try(|input| border_image_slice::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| border_image_slice::parse(context, input)) { slice = Some(value); // Parse border image width and outset, if applicable. - let maybe_width_outset: Result<_, ParseError> = input.try(|input| { + let maybe_width_outset: Result<_, ParseError> = input.try_parse(|input| { input.expect_delim('/')?; // Parse border image width, if applicable. - let w = input.try(|input| + let w = input.try_parse(|input| border_image_width::parse(context, input)).ok(); // Parse border image outset if applicable. - let o = input.try(|input| { + let o = input.try_parse(|input| { input.expect_delim('/')?; border_image_outset::parse(context, input) }).ok(); @@ -339,7 +339,7 @@ pub fn parse_border<'i, 't>( } % for name in "source repeat".split(): if ${name}.is_none() { - if let Ok(value) = input.try(|input| border_image_${name}::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| border_image_${name}::parse(context, input)) { ${name} = Some(value); continue } @@ -407,7 +407,7 @@ pub fn parse_border<'i, 't>( ) -> Result> { let start_value = border_${axis}_start_${prop}::parse(context, input)?; let end_value = - input.try(|input| border_${axis}_start_${prop}::parse(context, input)) + input.try_parse(|input| border_${axis}_start_${prop}::parse(context, input)) .unwrap_or_else(|_| start_value.clone()); Ok(expanded! { diff --git a/components/style/properties/shorthands/box.mako.rs b/components/style/properties/shorthands/box.mako.rs index c5cc80829c7..e1b94e52ac3 100644 --- a/components/style/properties/shorthands/box.mako.rs +++ b/components/style/properties/shorthands/box.mako.rs @@ -31,7 +31,7 @@ ${helpers.two_properties_shorthand( macro_rules! try_parse_one { ($context: expr, $input: expr, $var: ident, $prop_module: ident) => { if $var.is_none() { - if let Ok(value) = $input.try(|i| { + if let Ok(value) = $input.try_parse(|i| { $prop_module::single_value::parse($context, i) }) { $var = Some(value); @@ -85,12 +85,12 @@ macro_rules! try_parse_one { // Must check 'transition-property' after 'transition-timing-function' since // 'transition-property' accepts any keyword. if property.is_none() { - if let Ok(value) = input.try(|i| TransitionProperty::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| TransitionProperty::parse(context, i)) { property = Some(Some(value)); continue; } - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { // 'none' is not a valid value for , // so it's not acceptable in the function above. property = Some(None); @@ -389,13 +389,13 @@ ${helpers.two_properties_shorthand( let mut offset_rotate = None; loop { if offset_distance.is_none() { - if let Ok(value) = input.try(|i| LengthPercentage::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| LengthPercentage::parse(context, i)) { offset_distance = Some(value); } } if offset_rotate.is_none() { - if let Ok(value) = input.try(|i| OffsetRotate::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| OffsetRotate::parse(context, i)) { offset_rotate = Some(value); continue; } @@ -403,7 +403,7 @@ ${helpers.two_properties_shorthand( break; } - let offset_anchor = input.try(|i| { + let offset_anchor = input.try_parse(|i| { i.expect_delim('/')?; PositionOrAuto::parse(context, i) }).ok(); @@ -454,7 +454,7 @@ ${helpers.two_properties_shorthand( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let zoom = match input.try(|input| NumberOrPercentage::parse(context, input)) { + let zoom = match input.try_parse(|input| NumberOrPercentage::parse(context, input)) { Ok(number_or_percent) => number_or_percent.to_number(), Err(..) => { input.expect_ident_matching("normal")?; diff --git a/components/style/properties/shorthands/column.mako.rs b/components/style/properties/shorthands/column.mako.rs index d5e385faa4c..e7c775dff04 100644 --- a/components/style/properties/shorthands/column.mako.rs +++ b/components/style/properties/shorthands/column.mako.rs @@ -22,21 +22,21 @@ let mut autos = 0; loop { - if input.try(|input| input.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("auto")).is_ok() { // Leave the options to None, 'auto' is the initial value. autos += 1; continue } if column_count.is_none() { - if let Ok(value) = input.try(|input| column_count::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| column_count::parse(context, input)) { column_count = Some(value); continue } } if column_width.is_none() { - if let Ok(value) = input.try(|input| column_width::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| column_width::parse(context, input)) { column_width = Some(value); continue } @@ -80,7 +80,7 @@ loop { % for name in "width style color".split(): if column_rule_${name}.is_none() { - if let Ok(value) = input.try(|input| + if let Ok(value) = input.try_parse(|input| column_rule_${name}::parse(context, input)) { column_rule_${name} = Some(value); any = true; diff --git a/components/style/properties/shorthands/font.mako.rs b/components/style/properties/shorthands/font.mako.rs index 1feed113875..176164c4b1e 100644 --- a/components/style/properties/shorthands/font.mako.rs +++ b/components/style/properties/shorthands/font.mako.rs @@ -65,7 +65,7 @@ let mut stretch = None; let size; % if engine == "gecko": - if let Ok(sys) = input.try(SystemFont::parse) { + if let Ok(sys) = input.try_parse(SystemFont::parse) { return Ok(expanded! { % for name in SYSTEM_FONT_LONGHANDS: % if name == "font_size": @@ -83,30 +83,30 @@ // Special-case 'normal' because it is valid in each of // font-style, font-weight, font-variant and font-stretch. // Leaves the values to None, 'normal' is the initial value for each of them. - if input.try(|input| input.expect_ident_matching("normal")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("normal")).is_ok() { nb_normals += 1; continue; } if style.is_none() { - if let Ok(value) = input.try(|input| font_style::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| font_style::parse(context, input)) { style = Some(value); continue } } if weight.is_none() { - if let Ok(value) = input.try(|input| font_weight::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| font_weight::parse(context, input)) { weight = Some(value); continue } } if variant_caps.is_none() { - if let Ok(value) = input.try(|input| font_variant_caps::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| font_variant_caps::parse(context, input)) { variant_caps = Some(value); continue } } if stretch.is_none() { - if let Ok(value) = input.try(FontStretchKeyword::parse) { + if let Ok(value) = input.try_parse(FontStretchKeyword::parse) { stretch = Some(FontStretch::Keyword(value)); continue } @@ -122,7 +122,7 @@ } }; - let line_height = if input.try(|input| input.expect_delim('/')).is_ok() { + let line_height = if input.try_parse(|input| input.expect_delim('/')).is_ok() { Some(LineHeight::parse(context, input)?) } else { None @@ -325,9 +325,9 @@ let mut ${prop} = None; % endfor - if input.try(|input| input.expect_ident_matching("normal")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("normal")).is_ok() { // Leave the values to None, 'normal' is the initial value for all the sub properties. - } else if input.try(|input| input.expect_ident_matching("none")).is_ok() { + } else if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { // The 'none' value sets 'font-variant-ligatures' to 'none' and resets all other sub properties // to their initial value. % if engine == "gecko": @@ -336,13 +336,13 @@ } else { let mut has_custom_value: bool = false; loop { - if input.try(|input| input.expect_ident_matching("normal")).is_ok() || - input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("normal")).is_ok() || + input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)) } % for prop in sub_properties: if ${prop}.is_none() { - if let Ok(value) = input.try(|i| font_variant_${prop}::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| font_variant_${prop}::parse(context, i)) { has_custom_value = true; ${prop} = Some(value); continue diff --git a/components/style/properties/shorthands/inherited_text.mako.rs b/components/style/properties/shorthands/inherited_text.mako.rs index b9a0c008bac..9eb278da05c 100644 --- a/components/style/properties/shorthands/inherited_text.mako.rs +++ b/components/style/properties/shorthands/inherited_text.mako.rs @@ -22,13 +22,13 @@ loop { if color.is_none() { - if let Ok(value) = input.try(|input| text_emphasis_color::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| text_emphasis_color::parse(context, input)) { color = Some(value); continue } } if style.is_none() { - if let Ok(value) = input.try(|input| text_emphasis_style::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| text_emphasis_style::parse(context, input)) { style = Some(value); continue } @@ -64,14 +64,14 @@ let mut width = None; loop { if color.is_none() { - if let Ok(value) = input.try(|input| _webkit_text_stroke_color::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| _webkit_text_stroke_color::parse(context, input)) { color = Some(value); continue } } if width.is_none() { - if let Ok(value) = input.try(|input| _webkit_text_stroke_width::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| _webkit_text_stroke_width::parse(context, input)) { width = Some(value); continue } diff --git a/components/style/properties/shorthands/list.mako.rs b/components/style/properties/shorthands/list.mako.rs index 8e842cd153e..0b5a24df98f 100644 --- a/components/style/properties/shorthands/list.mako.rs +++ b/components/style/properties/shorthands/list.mako.rs @@ -21,7 +21,7 @@ let mut nones = 0u8; let (mut image, mut position, mut list_style_type, mut any) = (None, None, None, false); loop { - if input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { nones = nones + 1; if nones > 2 { return Err(input.new_custom_error(SelectorParseErrorKind::UnexpectedIdent("none".into()))) @@ -31,7 +31,7 @@ } if image.is_none() { - if let Ok(value) = input.try(|input| list_style_image::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| list_style_image::parse(context, input)) { image = Some(value); any = true; continue @@ -39,7 +39,7 @@ } if position.is_none() { - if let Ok(value) = input.try(|input| list_style_position::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| list_style_position::parse(context, input)) { position = Some(value); any = true; continue @@ -50,7 +50,7 @@ // arbitrary identifier for custom counter style, and thus may // affect values of list-style-position. if list_style_type.is_none() { - if let Ok(value) = input.try(|input| list_style_type::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| list_style_type::parse(context, input)) { list_style_type = Some(value); any = true; continue diff --git a/components/style/properties/shorthands/outline.mako.rs b/components/style/properties/shorthands/outline.mako.rs index d667aa9ffb1..c6ba47303a7 100644 --- a/components/style/properties/shorthands/outline.mako.rs +++ b/components/style/properties/shorthands/outline.mako.rs @@ -24,21 +24,21 @@ let mut any = false; loop { if color.is_none() { - if let Ok(value) = input.try(|i| specified::Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| specified::Color::parse(context, i)) { color = Some(value); any = true; continue } } if style.is_none() { - if let Ok(value) = input.try(|input| outline_style::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| outline_style::parse(context, input)) { style = Some(value); any = true; continue } } if width.is_none() { - if let Ok(value) = input.try(|input| outline_width::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| outline_width::parse(context, input)) { width = Some(value); any = true; continue diff --git a/components/style/properties/shorthands/position.mako.rs b/components/style/properties/shorthands/position.mako.rs index ff9b5cd5790..0dacdc4c7cf 100644 --- a/components/style/properties/shorthands/position.mako.rs +++ b/components/style/properties/shorthands/position.mako.rs @@ -21,13 +21,13 @@ let mut wrap = None; loop { if direction.is_none() { - if let Ok(value) = input.try(|input| flex_direction::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| flex_direction::parse(context, input)) { direction = Some(value); continue } } if wrap.is_none() { - if let Ok(value) = input.try(|input| flex_wrap::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| flex_wrap::parse(context, input)) { wrap = Some(value); continue } @@ -61,7 +61,7 @@ input: &mut Parser<'i, 't>, ) -> Result<(NonNegativeNumber, Option),ParseError<'i>> { let grow = NonNegativeNumber::parse(context, input)?; - let shrink = input.try(|i| NonNegativeNumber::parse(context, i)).ok(); + let shrink = input.try_parse(|i| NonNegativeNumber::parse(context, i)).ok(); Ok((grow, shrink)) } @@ -73,7 +73,7 @@ let mut shrink = None; let mut basis = None; - if input.try(|input| input.expect_ident_matching("none")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() { return Ok(expanded! { flex_grow: NonNegativeNumber::new(0.0), flex_shrink: NonNegativeNumber::new(0.0), @@ -82,14 +82,14 @@ } loop { if grow.is_none() { - if let Ok((flex_grow, flex_shrink)) = input.try(|i| parse_flexibility(context, i)) { + if let Ok((flex_grow, flex_shrink)) = input.try_parse(|i| parse_flexibility(context, i)) { grow = Some(flex_grow); shrink = flex_shrink; continue } } if basis.is_none() { - if let Ok(value) = input.try(|input| FlexBasis::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| FlexBasis::parse(context, input)) { basis = Some(value); continue } @@ -124,7 +124,7 @@ pub fn parse_value<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>) -> Result> { let r_gap = row_gap::parse(context, input)?; - let c_gap = input.try(|input| column_gap::parse(context, input)).unwrap_or(r_gap.clone()); + let c_gap = input.try_parse(|input| column_gap::parse(context, input)).unwrap_or(r_gap.clone()); Ok(expanded! { row_gap: r_gap, @@ -164,8 +164,8 @@ context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let start = input.try(|i| GridLine::parse(context, i))?; - let end = if input.try(|i| i.expect_delim('/')).is_ok() { + let start = input.try_parse(|i| GridLine::parse(context, i))?; + let end = if input.try_parse(|i| i.expect_delim('/')).is_ok() { GridLine::parse(context, input)? } else { let mut line = GridLine::auto(); @@ -226,12 +226,12 @@ this } - let row_start = input.try(|i| GridLine::parse(context, i))?; - let (column_start, row_end, column_end) = if input.try(|i| i.expect_delim('/')).is_ok() { + let row_start = input.try_parse(|i| GridLine::parse(context, i))?; + let (column_start, row_end, column_end) = if input.try_parse(|i| i.expect_delim('/')).is_ok() { let column_start = GridLine::parse(context, input)?; - let (row_end, column_end) = if input.try(|i| i.expect_delim('/')).is_ok() { + let (row_end, column_end) = if input.try_parse(|i| i.expect_delim('/')).is_ok() { let row_end = GridLine::parse(context, input)?; - let column_end = if input.try(|i| i.expect_delim('/')).is_ok() { + let column_end = if input.try_parse(|i| i.expect_delim('/')).is_ok() { GridLine::parse(context, input)? } else { // grid-column-end has not been given line_with_ident_from(&column_start) @@ -324,8 +324,8 @@ } %> % for keyword, rust_type in keywords.items(): - if let Ok(x) = input.try(|i| { - if i.try(|i| i.expect_ident_matching("${keyword}")).is_ok() { + if let Ok(x) = input.try_parse(|i| { + if i.try_parse(|i| i.expect_ident_matching("${keyword}")).is_ok() { if !i.is_exhausted() { return Err(()); } @@ -337,20 +337,20 @@ } % endfor - let first_line_names = input.try(parse_line_names).unwrap_or_default(); - if let Ok(string) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { + let first_line_names = input.try_parse(parse_line_names).unwrap_or_default(); + if let Ok(string) = input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { let mut strings = vec![]; let mut values = vec![]; let mut line_names = vec![]; line_names.push(first_line_names); strings.push(string); loop { - let size = input.try(|i| TrackSize::parse(context, i)).unwrap_or_default(); + let size = input.try_parse(|i| TrackSize::parse(context, i)).unwrap_or_default(); values.push(TrackListValue::TrackSize(size)); - let mut names = input.try(parse_line_names).unwrap_or_default(); - let more_names = input.try(parse_line_names); + let mut names = input.try_parse(parse_line_names).unwrap_or_default(); + let more_names = input.try_parse(parse_line_names); - match input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { + match input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { Ok(string) => { strings.push(string); if let Ok(v) = more_names { @@ -387,7 +387,7 @@ auto_repeat_index: std::usize::MAX, }; - let template_cols = if input.try(|i| i.expect_delim('/')).is_ok() { + let template_cols = if input.try_parse(|i| i.expect_delim('/')).is_ok() { let value = GridTemplateComponent::parse_without_none(context, input)?; if let GenericGridTemplateComponent::TrackList(ref list) = value { if !list.is_explicit() { @@ -572,13 +572,13 @@ let mut dense = GridAutoFlow::empty(); for _ in 0..2 { - if input.try(|i| i.expect_ident_matching("auto-flow")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto-flow")).is_ok() { track = if is_row { Some(GridAutoFlow::ROW) } else { Some(GridAutoFlow::COLUMN) }; - } else if input.try(|i| i.expect_ident_matching("dense")).is_ok() { + } else if input.try_parse(|i| i.expect_ident_matching("dense")).is_ok() { dense = GridAutoFlow::DENSE } else { break @@ -592,18 +592,18 @@ } } - if let Ok((rows, cols, areas)) = input.try(|i| super::grid_template::parse_grid_template(context, i)) { + if let Ok((rows, cols, areas)) = input.try_parse(|i| super::grid_template::parse_grid_template(context, i)) { temp_rows = rows; temp_cols = cols; temp_areas = areas; - } else if let Ok(rows) = input.try(|i| GridTemplateComponent::parse(context, i)) { + } else if let Ok(rows) = input.try_parse(|i| GridTemplateComponent::parse(context, i)) { temp_rows = rows; input.expect_delim('/')?; flow = parse_auto_flow(input, false)?; auto_cols = grid_auto_columns::parse(context, input).unwrap_or_default(); } else { flow = parse_auto_flow(input, true)?; - auto_rows = input.try(|i| grid_auto_rows::parse(context, i)).unwrap_or_default(); + auto_rows = input.try_parse(|i| grid_auto_rows::parse(context, i)).unwrap_or_default(); input.expect_delim('/')?; temp_cols = GridTemplateComponent::parse(context, input)?; } @@ -710,7 +710,7 @@ let align_content = ContentDistribution::parse(input, AxisDirection::Block)?; - let justify_content = input.try(|input| { + let justify_content = input.try_parse(|input| { ContentDistribution::parse(input, AxisDirection::Inline) }); @@ -763,7 +763,7 @@ input: &mut Parser<'i, 't>, ) -> Result> { let align = SelfAlignment::parse(input, AxisDirection::Block)?; - let justify = input.try(|input| SelfAlignment::parse(input, AxisDirection::Inline)); + let justify = input.try_parse(|input| SelfAlignment::parse(input, AxisDirection::Inline)); let justify = match justify { Ok(v) => v, @@ -812,7 +812,7 @@ ) -> Result> { let align = AlignItems::parse(context, input)?; let justify = - input.try(|input| JustifyItems::parse(context, input)) + input.try_parse(|input| JustifyItems::parse(context, input)) .unwrap_or_else(|_| JustifyItems::from(align)); Ok(expanded! { diff --git a/components/style/properties/shorthands/svg.mako.rs b/components/style/properties/shorthands/svg.mako.rs index 6610968f24d..99461a51487 100644 --- a/components/style/properties/shorthands/svg.mako.rs +++ b/components/style/properties/shorthands/svg.mako.rs @@ -55,18 +55,18 @@ % endfor loop { if image.is_none() { - if let Ok(value) = input.try(|input| mask_image::single_value + if let Ok(value) = input.try_parse(|input| mask_image::single_value ::parse(context, input)) { image = Some(value); continue } } if position.is_none() { - if let Ok(value) = input.try(|input| Position::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| Position::parse(context, input)) { position = Some(value); // Parse mask size, if applicable. - size = input.try(|input| { + size = input.try_parse(|input| { input.expect_delim('/')?; mask_size::single_value::parse(context, input) }).ok(); @@ -76,7 +76,7 @@ } % for name in "repeat origin clip composite mode".split(): if ${name}.is_none() { - if let Ok(value) = input.try(|input| mask_${name}::single_value + if let Ok(value) = input.try_parse(|input| mask_${name}::single_value ::parse(context, input)) { ${name} = Some(value); continue diff --git a/components/style/properties/shorthands/text.mako.rs b/components/style/properties/shorthands/text.mako.rs index defbfaaf3c0..5c7d9c7655c 100644 --- a/components/style/properties/shorthands/text.mako.rs +++ b/components/style/properties/shorthands/text.mako.rs @@ -35,7 +35,7 @@ macro_rules! parse_component { ($value:ident, $module:ident) => ( if $value.is_none() { - if let Ok(value) = input.try(|input| $module::parse(context, input)) { + if let Ok(value) = input.try_parse(|input| $module::parse(context, input)) { $value = Some(value); any = true; continue; diff --git a/components/style/stylesheets/document_rule.rs b/components/style/stylesheets/document_rule.rs index 35c6b443fe2..2f8c5bc48d7 100644 --- a/components/style/stylesheets/document_rule.rs +++ b/components/style/stylesheets/document_rule.rs @@ -135,7 +135,7 @@ impl DocumentMatchingFunction { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(url) = input.try(|input| CssUrl::parse(context, input)) { + if let Ok(url) = input.try_parse(|input| CssUrl::parse(context, input)) { return Ok(DocumentMatchingFunction::Url(url)); } diff --git a/components/style/stylesheets/rule_parser.rs b/components/style/stylesheets/rule_parser.rs index 74425afafcd..0b01a5f7bdd 100644 --- a/components/style/stylesheets/rule_parser.rs +++ b/components/style/stylesheets/rule_parser.rs @@ -218,7 +218,7 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser<'a> { return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedNamespaceRule)) } - let prefix = input.try(|i| i.expect_ident_cloned()) + let prefix = input.try_parse(|i| i.expect_ident_cloned()) .map(|s| Prefix::from(s.as_ref())).ok(); let maybe_namespace = match input.expect_url_or_string() { Ok(url_or_string) => url_or_string, diff --git a/components/style/stylesheets/supports_rule.rs b/components/style/stylesheets/supports_rule.rs index 6a522bcdb74..d0aaa0a03d8 100644 --- a/components/style/stylesheets/supports_rule.rs +++ b/components/style/stylesheets/supports_rule.rs @@ -103,7 +103,7 @@ impl SupportsCondition { /// /// pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - if input.try(|i| i.expect_ident_matching("not")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("not")).is_ok() { let inner = SupportsCondition::parse_in_parens(input)?; return Ok(SupportsCondition::Not(Box::new(inner))); } @@ -129,7 +129,7 @@ impl SupportsCondition { loop { conditions.push(SupportsCondition::parse_in_parens(input)?); if input - .try(|input| input.expect_ident_matching(keyword)) + .try_parse(|input| input.expect_ident_matching(keyword)) .is_err() { // Did not find the expected keyword. @@ -175,20 +175,20 @@ impl SupportsCondition { fn parse_in_parens<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { // Whitespace is normally taken care of in `Parser::next`, // but we want to not include it in `pos` for the SupportsCondition::FutureSyntax cases. - while input.try(Parser::expect_whitespace).is_ok() {} + while input.try_parse(Parser::expect_whitespace).is_ok() {} let pos = input.position(); let location = input.current_source_location(); match *input.next()? { Token::ParenthesisBlock => { - let nested = - input.try(|input| input.parse_nested_block(parse_condition_or_declaration)); + let nested = input + .try_parse(|input| input.parse_nested_block(parse_condition_or_declaration)); if nested.is_ok() { return nested; } }, Token::Function(ref ident) => { let ident = ident.clone(); - let nested = input.try(|input| { + let nested = input.try_parse(|input| { input.parse_nested_block(|input| { SupportsCondition::parse_functional(&ident, input) }) @@ -239,7 +239,7 @@ fn eval_moz_bool_pref(_: &CStr, _: &ParserContext) -> bool { pub fn parse_condition_or_declaration<'i, 't>( input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(condition) = input.try(SupportsCondition::parse) { + if let Ok(condition) = input.try_parse(SupportsCondition::parse) { Ok(SupportsCondition::Parenthesized(Box::new(condition))) } else { Declaration::parse(input).map(SupportsCondition::Declaration) @@ -414,7 +414,7 @@ impl Declaration { PropertyDeclaration::parse_into(&mut declarations, id, &context, input) .map_err(|_| input.new_custom_error(())) })?; - let _ = input.try(parse_important); + let _ = input.try_parse(parse_important); Ok(()) }) .is_ok() diff --git a/components/style/stylesheets/viewport_rule.rs b/components/style/stylesheets/viewport_rule.rs index cd875eefb69..a6ad967b34c 100644 --- a/components/style/stylesheets/viewport_rule.rs +++ b/components/style/stylesheets/viewport_rule.rs @@ -267,7 +267,7 @@ fn parse_shorthand<'i, 't>( input: &mut Parser<'i, 't>, ) -> Result<(ViewportLength, ViewportLength), ParseError<'i>> { let min = ViewportLength::parse(context, input)?; - match input.try(|i| ViewportLength::parse(context, i)) { + match input.try_parse(|i| ViewportLength::parse(context, i)) { Err(_) => Ok((min.clone(), min)), Ok(max) => Ok((min, max)), } @@ -293,7 +293,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> { ($declaration:ident($parse:expr)) => { declaration!($declaration { value: $parse(input)?, - important: input.try(parse_important).is_ok(), + important: input.try_parse(parse_important).is_ok(), }) }; ($declaration:ident { value: $value:expr, important: $important:expr, }) => { @@ -311,7 +311,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> { }; (shorthand -> [$min:ident, $max:ident]) => {{ let shorthand = parse_shorthand(self.context, input)?; - let important = input.try(parse_important).is_ok(); + let important = input.try_parse(parse_important).is_ok(); Ok(vec![ declaration!($min { diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 57ca8e97a86..d0b14b7e3fa 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -358,7 +358,7 @@ pub enum GenericFontFamily { impl SingleFontFamily { /// Parse a font-family value. pub fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - if let Ok(value) = input.try(|i| i.expect_string_cloned()) { + if let Ok(value) = input.try_parse(|i| i.expect_string_cloned()) { return Ok(SingleFontFamily::FamilyName(FamilyName { name: Atom::from(&*value), syntax: FontFamilyNameSyntax::Quoted, @@ -393,7 +393,7 @@ impl SingleFontFamily { value.push(' '); value.push_str(&ident); } - while let Ok(ident) = input.try(|i| i.expect_ident_cloned()) { + while let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) { serialize_quoted = serialize_quoted || ident.contains(' '); value.push(' '); value.push_str(&ident); diff --git a/components/style/values/generics/font.rs b/components/style/values/generics/font.rs index 237e862d4aa..e19c796d17b 100644 --- a/components/style/values/generics/font.rs +++ b/components/style/values/generics/font.rs @@ -107,7 +107,10 @@ impl Parse for FontSettings { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(Self::normal()); } diff --git a/components/style/values/generics/grid.rs b/components/style/values/generics/grid.rs index a0970a6fbc0..7995bf044a3 100644 --- a/components/style/values/generics/grid.rs +++ b/components/style/values/generics/grid.rs @@ -131,7 +131,7 @@ impl Parse for GridLine { input: &mut Parser<'i, 't>, ) -> Result> { let mut grid_line = Self::auto(); - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(grid_line); } @@ -144,7 +144,7 @@ impl Parse for GridLine { for _ in 0..3 { // Maximum possible entities for let location = input.current_source_location(); - if input.try(|i| i.expect_ident_matching("span")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("span")).is_ok() { if grid_line.is_span { return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } @@ -154,7 +154,7 @@ impl Parse for GridLine { } grid_line.is_span = true; - } else if let Ok(i) = input.try(|i| specified::Integer::parse(context, i)) { + } else if let Ok(i) = input.try_parse(|i| specified::Integer::parse(context, i)) { // FIXME(emilio): Probably shouldn't reject if it's calc()... let value = i.value(); if value == 0 || val_before_span || !grid_line.line_num.is_zero() { @@ -165,7 +165,7 @@ impl Parse for GridLine { MIN_GRID_LINE, cmp::min(value, MAX_GRID_LINE), )); - } else if let Ok(name) = input.try(|i| i.expect_ident_cloned()) { + } else if let Ok(name) = input.try_parse(|i| i.expect_ident_cloned()) { if val_before_span || grid_line.ident != atom!("") { return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)); } @@ -432,7 +432,7 @@ impl Parse for RepeatCount { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(mut i) = input.try(|i| specified::Integer::parse_positive(context, i)) { + if let Ok(mut i) = input.try_parse(|i| specified::Integer::parse_positive(context, i)) { if i.value() > MAX_GRID_LINE { i = specified::Integer::new(MAX_GRID_LINE); } @@ -671,14 +671,14 @@ impl Parse for LineNameList { let mut fill_data = None; loop { - let repeat_parse_result = input.try(|input| { + let repeat_parse_result = input.try_parse(|input| { input.expect_function_matching("repeat")?; input.parse_nested_block(|input| { let count = RepeatCount::parse(context, input)?; input.expect_comma()?; let mut names_list = vec![]; names_list.push(parse_line_names(input)?); // there should be at least one - while let Ok(names) = input.try(parse_line_names) { + while let Ok(names) = input.try_parse(parse_line_names) { names_list.push(names); } Ok((names_list, count)) @@ -703,7 +703,7 @@ impl Parse for LineNameList { }, _ => return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)), } - } else if let Ok(names) = input.try(parse_line_names) { + } else if let Ok(names) = input.try_parse(parse_line_names) { line_names.push(names); } else { break; diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index bed574861cb..3ac358e7817 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -59,7 +59,7 @@ impl LengthPercentageOrAuto { &mut Parser<'i, 't>, ) -> Result>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(LengthPercentageOrAuto::Auto); } diff --git a/components/style/values/generics/mod.rs b/components/style/values/generics/mod.rs index 6689405b2b1..09a99432e17 100644 --- a/components/style/values/generics/mod.rs +++ b/components/style/values/generics/mod.rs @@ -101,13 +101,13 @@ impl Parse for CounterStyle { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(name) = input.try(|i| parse_counter_style_name(i)) { + if let Ok(name) = input.try_parse(|i| parse_counter_style_name(i)) { return Ok(CounterStyle::Name(name)); } input.expect_function_matching("symbols")?; input.parse_nested_block(|input| { let symbols_type = input - .try(SymbolsType::parse) + .try_parse(SymbolsType::parse) .unwrap_or(SymbolsType::Symbolic); let symbols = Symbols::parse(context, input)?; // There must be at least two symbols for alphabetic or diff --git a/components/style/values/generics/rect.rs b/components/style/values/generics/rect.rs index 5164bd77463..dee21459a77 100644 --- a/components/style/values/generics/rect.rs +++ b/components/style/values/generics/rect.rs @@ -55,7 +55,7 @@ where Parse: Fn(&ParserContext, &mut Parser<'i, 't>) -> Result>, { let first = parse(context, input)?; - let second = if let Ok(second) = input.try(|i| parse(context, i)) { + let second = if let Ok(second) = input.try_parse(|i| parse(context, i)) { second } else { // @@ -66,13 +66,13 @@ where first, )); }; - let third = if let Ok(third) = input.try(|i| parse(context, i)) { + let third = if let Ok(third) = input.try_parse(|i| parse(context, i)) { third } else { // return Ok(Self::new(first.clone(), second.clone(), first, second)); }; - let fourth = if let Ok(fourth) = input.try(|i| parse(context, i)) { + let fourth = if let Ok(fourth) = input.try_parse(|i| parse(context, i)) { fourth } else { // diff --git a/components/style/values/generics/size.rs b/components/style/values/generics/size.rs index fa129bee475..e00eef28b93 100644 --- a/components/style/values/generics/size.rs +++ b/components/style/values/generics/size.rs @@ -63,7 +63,7 @@ impl Size2D { { let first = parse_one(context, input)?; let second = input - .try(|i| parse_one(context, i)) + .try_parse(|i| parse_one(context, i)) .unwrap_or_else(|_| first.clone()); Ok(Self::new(first, second)) } diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 2b04d36db78..26a33228e86 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -129,7 +129,7 @@ impl Parse for SVGPaint { }); } let fallback = input - .try(|i| SVGPaintFallback::parse(context, i)) + .try_parse(|i| SVGPaintFallback::parse(context, i)) .unwrap_or(SVGPaintFallback::Unset); Ok(SVGPaint { kind, fallback }) } diff --git a/components/style/values/generics/text.rs b/components/style/values/generics/text.rs index ceeb59a3d0c..0062f304701 100644 --- a/components/style/values/generics/text.rs +++ b/components/style/values/generics/text.rs @@ -63,7 +63,10 @@ impl Spacing { where F: FnOnce(&ParserContext, &mut Parser<'i, 't>) -> Result>, { - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(Spacing::Normal); } parse(context, input).map(Spacing::Value) diff --git a/components/style/values/specified/align.rs b/components/style/values/specified/align.rs index 51b5e625672..ebb6f638340 100644 --- a/components/style/values/specified/align.rs +++ b/components/style/values/specified/align.rs @@ -194,25 +194,28 @@ impl ContentDistribution { // when this function is updated. // Try to parse normal first - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(ContentDistribution::normal()); } // Parse , but only on the block axis. if axis == AxisDirection::Block { - if let Ok(value) = input.try(parse_baseline) { + if let Ok(value) = input.try_parse(parse_baseline) { return Ok(ContentDistribution::new(value)); } } // - if let Ok(value) = input.try(parse_content_distribution) { + if let Ok(value) = input.try_parse(parse_content_distribution) { return Ok(ContentDistribution::new(value)); } // ? let overflow_position = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let content_position = try_match_ident_ignore_ascii_case! { input, @@ -426,18 +429,18 @@ impl SelfAlignment { // // It's weird that this accepts , but not // justify-content... - if let Ok(value) = input.try(parse_baseline) { + if let Ok(value) = input.try_parse(parse_baseline) { return Ok(SelfAlignment(value)); } // auto | normal | stretch - if let Ok(value) = input.try(parse_auto_normal_stretch) { + if let Ok(value) = input.try_parse(parse_auto_normal_stretch) { return Ok(SelfAlignment(value)); } // ? let overflow_position = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let self_position = parse_self_position(input, axis)?; Ok(SelfAlignment(overflow_position | self_position)) @@ -564,17 +567,17 @@ impl Parse for AlignItems { // this function is updated. // - if let Ok(baseline) = input.try(parse_baseline) { + if let Ok(baseline) = input.try_parse(parse_baseline) { return Ok(AlignItems(baseline)); } // normal | stretch - if let Ok(value) = input.try(parse_normal_stretch) { + if let Ok(value) = input.try_parse(parse_normal_stretch) { return Ok(AlignItems(value)); } // ? let overflow = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let self_position = parse_self_position(input, AxisDirection::Block)?; Ok(AlignItems(self_position | overflow)) @@ -623,23 +626,23 @@ impl Parse for JustifyItems { // // It's weird that this accepts , but not // justify-content... - if let Ok(baseline) = input.try(parse_baseline) { + if let Ok(baseline) = input.try_parse(parse_baseline) { return Ok(JustifyItems(baseline)); } // normal | stretch - if let Ok(value) = input.try(parse_normal_stretch) { + if let Ok(value) = input.try_parse(parse_normal_stretch) { return Ok(JustifyItems(value)); } // legacy | [ legacy && [ left | right | center ] ] - if let Ok(value) = input.try(parse_legacy) { + if let Ok(value) = input.try_parse(parse_legacy) { return Ok(JustifyItems(value)); } // ? let overflow = input - .try(parse_overflow_position) + .try_parse(parse_overflow_position) .unwrap_or(AlignFlags::empty()); let self_position = parse_self_position(input, AxisDirection::Inline)?; Ok(JustifyItems(overflow | self_position)) @@ -795,7 +798,7 @@ fn parse_legacy<'i, 't>(input: &mut Parser<'i, 't>) -> Result { - let flags = input.try(parse_left_right_center) + let flags = input.try_parse(parse_left_right_center) .unwrap_or(AlignFlags::empty()); return Ok(AlignFlags::LEGACY | flags) diff --git a/components/style/values/specified/background.rs b/components/style/values/specified/background.rs index e7cb98a6ae9..29f6d6b352f 100644 --- a/components/style/values/specified/background.rs +++ b/components/style/values/specified/background.rs @@ -22,9 +22,10 @@ impl Parse for BackgroundSize { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(width) = input.try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) { + if let Ok(width) = input.try_parse(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) + { let height = input - .try(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) + .try_parse(|i| NonNegativeLengthPercentageOrAuto::parse(context, i)) .unwrap_or(NonNegativeLengthPercentageOrAuto::auto()); return Ok(GenericBackgroundSize::ExplicitSize { width, height }); } @@ -136,7 +137,7 @@ impl Parse for BackgroundRepeat { }, }; - let vertical = input.try(BackgroundRepeatKeyword::parse).ok(); + let vertical = input.try_parse(BackgroundRepeatKeyword::parse).ok(); Ok(BackgroundRepeat(horizontal, vertical.unwrap_or(horizontal))) } } diff --git a/components/style/values/specified/basic_shape.rs b/components/style/values/specified/basic_shape.rs index 135ac85d330..37aaae2ec2a 100644 --- a/components/style/values/specified/basic_shape.rs +++ b/components/style/values/specified/basic_shape.rs @@ -83,7 +83,7 @@ where return false; // already parsed this component } - *component = input.try(|i| U::parse(context, i)).ok(); + *component = input.try_parse(|i| U::parse(context, i)).ok(); component.is_some() } @@ -112,17 +112,17 @@ impl Parse for ClipPath { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(ClipPath::None); } if is_clip_path_path_enabled(context) { - if let Ok(p) = input.try(|i| Path::parse(context, i)) { + if let Ok(p) = input.try_parse(|i| Path::parse(context, i)) { return Ok(ClipPath::Path(p)); } } - if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) { + if let Ok(url) = input.try_parse(|i| SpecifiedUrl::parse(context, i)) { return Ok(ClipPath::Url(url)); } @@ -138,11 +138,11 @@ impl Parse for ShapeOutside { ) -> Result> { // Need to parse this here so that `Image::parse_with_cors_anonymous` // doesn't parse it. - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(ShapeOutside::None); } - if let Ok(image) = input.try(|i| Image::parse_with_cors_anonymous(context, i)) { + if let Ok(image) = input.try_parse(|i| Image::parse_with_cors_anonymous(context, i)) { debug_assert_ne!(image, Image::None); return Ok(ShapeOutside::Image(image)); } @@ -189,7 +189,10 @@ impl InsetRect { input: &mut Parser<'i, 't>, ) -> Result> { let rect = Rect::parse_with(context, input, LengthPercentage::parse)?; - let round = if input.try(|i| i.expect_ident_matching("round")).is_ok() { + let round = if input + .try_parse(|i| i.expect_ident_matching("round")) + .is_ok() + { BorderRadius::parse(context, input)? } else { BorderRadius::zero() @@ -214,9 +217,9 @@ impl Circle { input: &mut Parser<'i, 't>, ) -> Result> { let radius = input - .try(|i| ShapeRadius::parse(context, i)) + .try_parse(|i| ShapeRadius::parse(context, i)) .unwrap_or_default(); - let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() { + let position = if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() { Position::parse(context, input)? } else { Position::center() @@ -242,14 +245,14 @@ impl Ellipse { input: &mut Parser<'i, 't>, ) -> Result> { let (a, b) = input - .try(|i| -> Result<_, ParseError> { + .try_parse(|i| -> Result<_, ParseError> { Ok(( ShapeRadius::parse(context, i)?, ShapeRadius::parse(context, i)?, )) }) .unwrap_or_default(); - let position = if input.try(|i| i.expect_ident_matching("at")).is_ok() { + let position = if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() { Position::parse(context, input)? } else { Position::center() @@ -280,7 +283,7 @@ impl Polygon { input: &mut Parser<'i, 't>, ) -> Result> { let fill = input - .try(|i| -> Result<_, ParseError> { + .try_parse(|i| -> Result<_, ParseError> { let fill = FillRule::parse(i)?; i.expect_comma()?; // only eat the comma if there is something before it Ok(fill) @@ -317,7 +320,7 @@ impl Path { input: &mut Parser<'i, 't>, ) -> Result> { let fill = input - .try(|i| -> Result<_, ParseError> { + .try_parse(|i| -> Result<_, ParseError> { let fill = FillRule::parse(i)?; i.expect_comma()?; Ok(fill) diff --git a/components/style/values/specified/border.rs b/components/style/values/specified/border.rs index 28be8177cf4..817a5aadddb 100644 --- a/components/style/values/specified/border.rs +++ b/components/style/values/specified/border.rs @@ -121,7 +121,8 @@ impl BorderSideWidth { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if let Ok(length) = input.try(|i| NonNegativeLength::parse_quirky(context, i, allow_quirks)) + if let Ok(length) = + input.try_parse(|i| NonNegativeLength::parse_quirky(context, i, allow_quirks)) { return Ok(BorderSideWidth::Length(length)); } @@ -178,10 +179,10 @@ impl Parse for BorderImageSlice { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let mut fill = input.try(|i| i.expect_ident_matching("fill")).is_ok(); + let mut fill = input.try_parse(|i| i.expect_ident_matching("fill")).is_ok(); let offsets = Rect::parse_with(context, input, NonNegativeNumberOrPercentage::parse)?; if !fill { - fill = input.try(|i| i.expect_ident_matching("fill")).is_ok(); + fill = input.try_parse(|i| i.expect_ident_matching("fill")).is_ok(); } Ok(GenericBorderImageSlice { offsets, fill }) } @@ -193,7 +194,7 @@ impl Parse for BorderRadius { input: &mut Parser<'i, 't>, ) -> Result> { let widths = Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)?; - let heights = if input.try(|i| i.expect_delim('/')).is_ok() { + let heights = if input.try_parse(|i| i.expect_delim('/')).is_ok() { Rect::parse_with(context, input, NonNegativeLengthPercentage::parse)? } else { widths.clone() @@ -301,7 +302,7 @@ impl Parse for BorderImageRepeat { input: &mut Parser<'i, 't>, ) -> Result> { let horizontal = BorderImageRepeatKeyword::parse(input)?; - let vertical = input.try(BorderImageRepeatKeyword::parse).ok(); + let vertical = input.try_parse(BorderImageRepeatKeyword::parse).ok(); Ok(BorderImageRepeat( horizontal, vertical.unwrap_or(horizontal), diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 212ea92f10b..676262500f0 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -530,30 +530,30 @@ impl Parse for Display { input: &mut Parser<'i, 't>, ) -> Result> { // Parse all combinations of ? and `list-item`? first. - let mut got_list_item = input.try(parse_list_item).is_ok(); + let mut got_list_item = input.try_parse(parse_list_item).is_ok(); let mut inside = if got_list_item { - input.try(parse_display_inside_for_list_item) + input.try_parse(parse_display_inside_for_list_item) } else { - input.try(parse_display_inside) + input.try_parse(parse_display_inside) }; // = ? && [ flow | flow-root ]? && list-item // https://drafts.csswg.org/css-display/#typedef-display-listitem if !got_list_item && is_valid_inside_for_list_item(&inside) { - got_list_item = input.try(parse_list_item).is_ok(); + got_list_item = input.try_parse(parse_list_item).is_ok(); } - let outside = input.try(parse_display_outside); + let outside = input.try_parse(parse_display_outside); if outside.is_ok() { if !got_list_item && (inside.is_err() || is_valid_inside_for_list_item(&inside)) { - got_list_item = input.try(parse_list_item).is_ok(); + got_list_item = input.try_parse(parse_list_item).is_ok(); } if inside.is_err() { inside = if got_list_item { - input.try(parse_display_inside_for_list_item) + input.try_parse(parse_display_inside_for_list_item) } else { - input.try(parse_display_inside) + input.try_parse(parse_display_inside) }; if !got_list_item && is_valid_inside_for_list_item(&inside) { - got_list_item = input.try(parse_list_item).is_ok(); + got_list_item = input.try_parse(parse_list_item).is_ok(); } } } @@ -677,7 +677,8 @@ impl Parse for VerticalAlign { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) + if let Ok(lp) = + input.try_parse(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes)) { return Ok(GenericVerticalAlign::Length(lp)); } @@ -697,7 +698,7 @@ impl Parse for AnimationIterationCount { input: &mut ::cssparser::Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("infinite")) + .try_parse(|input| input.expect_ident_matching("infinite")) .is_ok() { return Ok(GenericAnimationIterationCount::Infinite); @@ -761,7 +762,7 @@ impl Parse for AnimationName { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(name) = input.try(|input| KeyframesName::parse(context, input)) { + if let Ok(name) = input.try_parse(|input| KeyframesName::parse(context, input)) { return Ok(AnimationName(Some(name))); } @@ -860,7 +861,7 @@ impl Parse for ScrollSnapType { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(ScrollSnapType::none()); @@ -868,7 +869,7 @@ impl Parse for ScrollSnapType { let axis = ScrollSnapAxis::parse(input)?; let strictness = input - .try(ScrollSnapStrictness::parse) + .try_parse(ScrollSnapStrictness::parse) .unwrap_or(ScrollSnapStrictness::Proximity); Ok(Self { axis, strictness }) } @@ -955,7 +956,9 @@ impl Parse for ScrollSnapAlign { input: &mut Parser<'i, 't>, ) -> Result> { let block = ScrollSnapAlignKeyword::parse(input)?; - let inline = input.try(ScrollSnapAlignKeyword::parse).unwrap_or(block); + let inline = input + .try_parse(ScrollSnapAlignKeyword::parse) + .unwrap_or(block); Ok(ScrollSnapAlign { block, inline }) } } @@ -1150,7 +1153,7 @@ impl Parse for WillChange { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("auto")) + .try_parse(|input| input.expect_ident_matching("auto")) .is_ok() { return Ok(Self::default()); @@ -1238,14 +1241,14 @@ impl Parse for TouchAction { "none" => Ok(TouchAction::NONE), "manipulation" => Ok(TouchAction::MANIPULATION), "pan-x" => { - if input.try(|i| i.expect_ident_matching("pan-y")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("pan-y")).is_ok() { Ok(TouchAction::PAN_X | TouchAction::PAN_Y) } else { Ok(TouchAction::PAN_X) } }, "pan-y" => { - if input.try(|i| i.expect_ident_matching("pan-x")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("pan-x")).is_ok() { Ok(TouchAction::PAN_X | TouchAction::PAN_Y) } else { Ok(TouchAction::PAN_Y) @@ -1323,7 +1326,7 @@ impl Parse for Contain { input: &mut Parser<'i, 't>, ) -> Result> { let mut result = Contain::empty(); - while let Ok(name) = input.try(|i| i.expect_ident_cloned()) { + while let Ok(name) = input.try_parse(|i| i.expect_ident_cloned()) { let flag = match_ignore_ascii_case! { &name, "size" => Some(Contain::SIZE), "layout" => Some(Contain::LAYOUT), diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index e697f2523c9..3be551d27a4 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -356,7 +356,7 @@ impl Parse for Color { input.reset(&start); let compontent_parser = ColorComponentParser(&*context); - match input.try(|i| CSSParserColor::parse_with(&compontent_parser, i)) { + match input.try_parse(|i| CSSParserColor::parse_with(&compontent_parser, i)) { Ok(value) => Ok(match value { CSSParserColor::CurrentColor => Color::CurrentColor, CSSParserColor::RGBA(rgba) => Color::Numeric { @@ -367,7 +367,7 @@ impl Parse for Color { Err(e) => { #[cfg(feature = "gecko")] { - if let Ok(system) = input.try(|i| SystemColor::parse(context, i)) { + if let Ok(system) = input.try_parse(|i| SystemColor::parse(context, i)) { return Ok(Color::System(system)); } } @@ -451,7 +451,7 @@ impl Color { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - input.try(|i| Self::parse(context, i)).or_else(|e| { + input.try_parse(|i| Self::parse(context, i)).or_else(|e| { if !allow_quirks.allowed(context.quirks_mode) { return Err(e); } diff --git a/components/style/values/specified/counters.rs b/components/style/values/specified/counters.rs index 0ecc79fb041..ac097c91a9b 100644 --- a/components/style/values/specified/counters.rs +++ b/components/style/values/specified/counters.rs @@ -50,7 +50,7 @@ fn parse_counters<'i, 't>( default_value: i32, ) -> Result>, ParseError<'i>> { if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(vec![]); @@ -69,7 +69,7 @@ fn parse_counters<'i, 't>( }; let value = input - .try(|input| Integer::parse(context, input)) + .try_parse(|input| Integer::parse(context, input)) .unwrap_or(Integer::new(default_value)); counters.push(CounterPair { name, value }); } @@ -91,7 +91,7 @@ impl Content { #[cfg(feature = "servo")] fn parse_counter_style(_: &ParserContext, input: &mut Parser) -> ListStyleType { input - .try(|input| { + .try_parse(|input| { input.expect_comma()?; ListStyleType::parse(input) }) @@ -101,7 +101,7 @@ impl Content { #[cfg(feature = "gecko")] fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyle { input - .try(|input| { + .try_parse(|input| { input.expect_comma()?; CounterStyle::parse(context, input) }) @@ -119,13 +119,13 @@ impl Parse for Content { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(generics::Content::Normal); } if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(generics::Content::None); @@ -136,7 +136,7 @@ impl Parse for Content { loop { #[cfg(any(feature = "gecko", feature = "servo-layout-2020"))] { - if let Ok(url) = input.try(|i| SpecifiedImageUrl::parse(context, i)) { + if let Ok(url) = input.try_parse(|i| SpecifiedImageUrl::parse(context, i)) { content.push(generics::ContentItem::Url(url)); continue; } diff --git a/components/style/values/specified/easing.rs b/components/style/values/specified/easing.rs index 2344e846ea3..26b921ebdc4 100644 --- a/components/style/values/specified/easing.rs +++ b/components/style/values/specified/easing.rs @@ -21,10 +21,10 @@ impl Parse for TimingFunction { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(keyword) = input.try(TimingKeyword::parse) { + if let Ok(keyword) = input.try_parse(TimingKeyword::parse) { return Ok(GenericTimingFunction::Keyword(keyword)); } - if let Ok(ident) = input.try(|i| i.expect_ident_cloned()) { + if let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) { let position = match_ignore_ascii_case! { &ident, "step-start" => StepPosition::Start, "step-end" => StepPosition::End, @@ -57,7 +57,7 @@ impl Parse for TimingFunction { }, "steps" => { let steps = Integer::parse_positive(context, i)?; - let position = i.try(|i| { + let position = i.try_parse(|i| { i.expect_comma()?; StepPosition::parse(context, i) }).unwrap_or(StepPosition::End); diff --git a/components/style/values/specified/effects.rs b/components/style/values/specified/effects.rs index c10445fa62f..87578b127e6 100644 --- a/components/style/values/specified/effects.rs +++ b/components/style/values/specified/effects.rs @@ -141,7 +141,7 @@ impl Parse for BoxShadow { loop { if !inset { if input - .try(|input| input.expect_ident_matching("inset")) + .try_parse(|input| input.expect_ident_matching("inset")) .is_ok() { inset = true; @@ -156,7 +156,7 @@ impl Parse for BoxShadow { .try::<_, _, ParseError>(|i| Length::parse_non_negative(context, i)) { Ok(blur) => { - let spread = i.try(|i| Length::parse(context, i)).ok(); + let spread = i.try_parse(|i| Length::parse(context, i)).ok(); (Some(blur.into()), spread) }, Err(_) => (None, None), @@ -169,7 +169,7 @@ impl Parse for BoxShadow { } } if color.is_none() { - if let Ok(value) = input.try(|i| Color::parse(context, i)) { + if let Ok(value) = input.try_parse(|i| Color::parse(context, i)) { color = Some(value); continue; } @@ -226,7 +226,7 @@ impl Parse for Filter { ) -> Result> { #[cfg(feature = "gecko")] { - if let Ok(url) = input.try(|i| SpecifiedUrl::parse(context, i)) { + if let Ok(url) = input.try_parse(|i| SpecifiedUrl::parse(context, i)) { return Ok(GenericFilter::Url(url)); } } @@ -242,22 +242,22 @@ impl Parse for Filter { input.parse_nested_block(|i| { match_ignore_ascii_case! { &*function, "blur" => Ok(GenericFilter::Blur( - i.try(|i| NonNegativeLength::parse(context, i)) + i.try_parse(|i| NonNegativeLength::parse(context, i)) .unwrap_or(Zero::zero()), )), "brightness" => Ok(GenericFilter::Brightness( - i.try(|i| NonNegativeFactor::parse(context, i)) + i.try_parse(|i| NonNegativeFactor::parse(context, i)) .unwrap_or(NonNegativeFactor::one()), )), "contrast" => Ok(GenericFilter::Contrast( - i.try(|i| NonNegativeFactor::parse(context, i)) + i.try_parse(|i| NonNegativeFactor::parse(context, i)) .unwrap_or(NonNegativeFactor::one()), )), "grayscale" => { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-grayscale Ok(GenericFilter::Grayscale( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, @@ -265,7 +265,7 @@ impl Parse for Filter { // We allow unitless zero here, see: // https://github.com/w3c/fxtf-drafts/issues/228 Ok(GenericFilter::HueRotate( - i.try(|i| Angle::parse_with_unitless(context, i)) + i.try_parse(|i| Angle::parse_with_unitless(context, i)) .unwrap_or(Zero::zero()), )) }, @@ -273,7 +273,7 @@ impl Parse for Filter { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-invert Ok(GenericFilter::Invert( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, @@ -281,19 +281,19 @@ impl Parse for Filter { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-opacity Ok(GenericFilter::Opacity( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, "saturate" => Ok(GenericFilter::Saturate( - i.try(|i| NonNegativeFactor::parse(context, i)) + i.try_parse(|i| NonNegativeFactor::parse(context, i)) .unwrap_or(NonNegativeFactor::one()), )), "sepia" => { // Values of amount over 100% are allowed but UAs must clamp the values to 1. // https://drafts.fxtf.org/filter-effects/#funcdef-filter-sepia Ok(GenericFilter::Sepia( - i.try(|i| ZeroToOneFactor::parse(context, i)) + i.try_parse(|i| ZeroToOneFactor::parse(context, i)) .unwrap_or(ZeroToOneFactor::one()), )) }, @@ -312,12 +312,14 @@ impl Parse for SimpleShadow { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - let color = input.try(|i| Color::parse(context, i)).ok(); + let color = input.try_parse(|i| Color::parse(context, i)).ok(); let horizontal = Length::parse(context, input)?; let vertical = Length::parse(context, input)?; - let blur = input.try(|i| Length::parse_non_negative(context, i)).ok(); + let blur = input + .try_parse(|i| Length::parse_non_negative(context, i)) + .ok(); let blur = blur.map(NonNegative::); - let color = color.or_else(|| input.try(|i| Color::parse(context, i)).ok()); + let color = color.or_else(|| input.try_parse(|i| Color::parse(context, i)).ok()); Ok(SimpleShadow { color, diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 39233dfc572..8ab48bfaf21 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -171,7 +171,7 @@ impl Parse for AbsoluteFontWeight { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(number) = input.try(|input| Number::parse(context, input)) { + if let Ok(number) = input.try_parse(|input| Number::parse(context, input)) { // We could add another AllowedNumericType value, but it doesn't // seem worth it just for a single property with such a weird range, // so we do the clamping here manually. @@ -223,7 +223,7 @@ impl Parse for SpecifiedFontStyle { "normal" => generics::FontStyle::Normal, "italic" => generics::FontStyle::Italic, "oblique" => { - let angle = input.try(|input| Self::parse_angle(context, input)) + let angle = input.try_parse(|input| Self::parse_angle(context, input)) .unwrap_or_else(|_| Self::default_angle()); generics::FontStyle::Oblique(angle) @@ -453,7 +453,9 @@ impl Parse for FontStretch { // // Values less than 0% are not allowed and are treated as parse // errors. - if let Ok(percentage) = input.try(|input| Percentage::parse_non_negative(context, input)) { + if let Ok(percentage) = + input.try_parse(|input| Percentage::parse_non_negative(context, input)) + { return Ok(FontStretch::Stretch(percentage)); } @@ -996,13 +998,13 @@ impl FontSize { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if let Ok(lp) = - input.try(|i| LengthPercentage::parse_non_negative_quirky(context, i, allow_quirks)) + if let Ok(lp) = input + .try_parse(|i| LengthPercentage::parse_non_negative_quirky(context, i, allow_quirks)) { return Ok(FontSize::Length(lp)); } - if let Ok(kw) = input.try(FontSizeKeyword::parse) { + if let Ok(kw) = input.try_parse(FontSizeKeyword::parse) { return Ok(FontSize::Keyword(KeywordInfo::new(kw))); } @@ -1155,7 +1157,7 @@ impl Parse for FontVariantAlternates { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantAlternates::Value(Default::default())); @@ -1171,7 +1173,7 @@ impl Parse for FontVariantAlternates { parsed_alternates |= $flag; ) ); - while let Ok(_) = input.try(|input| match *input.next()? { + while let Ok(_) = input.try_parse(|input| match *input.next()? { Token::Ident(ref value) if value.eq_ignore_ascii_case("historical-forms") => { check_if_parsed!(input, VariantAlternatesParsingFlags::HISTORICAL_FORMS); alternates.push(VariantAlternates::HistoricalForms); @@ -1386,13 +1388,13 @@ impl Parse for FontVariantEastAsian { let mut result = VariantEastAsian::empty(); if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantEastAsian::Value(result)); } - while let Ok(flag) = input.try(|input| { + while let Ok(flag) = input.try_parse(|input| { Ok( match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "jis78" => @@ -1610,19 +1612,19 @@ impl Parse for FontVariantLigatures { let mut result = VariantLigatures::empty(); if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantLigatures::Value(result)); } if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(FontVariantLigatures::Value(VariantLigatures::NONE)); } - while let Ok(flag) = input.try(|input| { + while let Ok(flag) = input.try_parse(|input| { Ok( match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "common-ligatures" => @@ -1819,13 +1821,13 @@ impl Parse for FontVariantNumeric { let mut result = VariantNumeric::empty(); if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontVariantNumeric::Value(result)); } - while let Ok(flag) = input.try(|input| { + while let Ok(flag) = input.try_parse(|input| { Ok( match_ignore_ascii_case! { &input.expect_ident().map_err(|_| ())?, "ordinal" => @@ -1969,14 +1971,14 @@ impl Parse for FontSynthesis { "none" => Ok(result), "weight" => { result.weight = true; - if input.try(|input| input.expect_ident_matching("style")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("style")).is_ok() { result.style = true; } Ok(result) }, "style" => { result.style = true; - if input.try(|input| input.expect_ident_matching("weight")).is_ok() { + if input.try_parse(|input| input.expect_ident_matching("weight")).is_ok() { result.weight = true; } Ok(result) @@ -2096,7 +2098,7 @@ impl Parse for FontLanguageOverride { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("normal")) + .try_parse(|input| input.expect_ident_matching("normal")) .is_ok() { return Ok(FontLanguageOverride::Normal); @@ -2163,7 +2165,7 @@ fn parse_one_feature_value<'i, 't>( context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(integer) = input.try(|i| Integer::parse_non_negative(context, i)) { + if let Ok(integer) = input.try_parse(|i| Integer::parse_non_negative(context, i)) { return Ok(integer); } @@ -2181,7 +2183,7 @@ impl Parse for FeatureTagValue { ) -> Result> { let tag = FontTag::parse(context, input)?; let value = input - .try(|i| parse_one_feature_value(context, i)) + .try_parse(|i| parse_one_feature_value(context, i)) .unwrap_or_else(|_| Integer::new(1)); Ok(Self { tag, value }) @@ -2318,7 +2320,7 @@ impl Parse for MozScriptLevel { input: &mut Parser<'i, 't>, ) -> Result> { // We don't bother to handle calc here. - if let Ok(i) = input.try(|i| i.expect_integer()) { + if let Ok(i) = input.try_parse(|i| i.expect_integer()) { return Ok(MozScriptLevel::Relative(i)); } input.expect_ident_matching("auto")?; diff --git a/components/style/values/specified/grid.rs b/components/style/values/specified/grid.rs index 9c6bf385d31..cfcba5dca35 100644 --- a/components/style/values/specified/grid.rs +++ b/components/style/values/specified/grid.rs @@ -52,11 +52,11 @@ impl Parse for TrackBreadth { // NonNegativeLengthPercentage instead. // // Though it seems these cannot be animated so it's ~ok. - if let Ok(lp) = input.try(|i| LengthPercentage::parse_non_negative(context, i)) { + if let Ok(lp) = input.try_parse(|i| LengthPercentage::parse_non_negative(context, i)) { return Ok(TrackBreadth::Breadth(lp)); } - if let Ok(f) = input.try(parse_flex) { + if let Ok(f) = input.try_parse(parse_flex) { return Ok(TrackBreadth::Fr(f)); } @@ -69,14 +69,17 @@ impl Parse for TrackSize { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(b) = input.try(|i| TrackBreadth::parse(context, i)) { + if let Ok(b) = input.try_parse(|i| TrackBreadth::parse(context, i)) { return Ok(TrackSize::Breadth(b)); } - if input.try(|i| i.expect_function_matching("minmax")).is_ok() { + if input + .try_parse(|i| i.expect_function_matching("minmax")) + .is_ok() + { return input.parse_nested_block(|input| { let inflexible_breadth = - match input.try(|i| LengthPercentage::parse_non_negative(context, i)) { + match input.try_parse(|i| LengthPercentage::parse_non_negative(context, i)) { Ok(lp) => TrackBreadth::Breadth(lp), Err(..) => TrackBreadth::parse_keyword(input)?, }; @@ -119,7 +122,7 @@ pub fn parse_line_names<'i, 't>( input.expect_square_bracket_block()?; input.parse_nested_block(|input| { let mut values = vec![]; - while let Ok((loc, ident)) = input.try(|i| -> Result<_, CssParseError<()>> { + while let Ok((loc, ident)) = input.try_parse(|i| -> Result<_, CssParseError<()>> { Ok((i.current_source_location(), i.expect_ident_cloned()?)) }) { let ident = CustomIdent::from_ident(loc, &ident, &["span", "auto"])?; @@ -150,7 +153,7 @@ impl TrackRepeat { input: &mut Parser<'i, 't>, ) -> Result<(Self, RepeatType), ParseError<'i>> { input - .try(|i| i.expect_function_matching("repeat").map_err(|e| e.into())) + .try_parse(|i| i.expect_function_matching("repeat").map_err(|e| e.into())) .and_then(|_| { input.parse_nested_block(|input| { let count = RepeatCount::parse(context, input)?; @@ -169,8 +172,8 @@ impl TrackRepeat { let mut current_names; loop { - current_names = input.try(parse_line_names).unwrap_or_default(); - if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) { + current_names = input.try_parse(parse_line_names).unwrap_or_default(); + if let Ok(track_size) = input.try_parse(|i| TrackSize::parse(context, i)) { if !track_size.is_fixed() { if is_auto { // should be for @@ -224,8 +227,9 @@ impl Parse for TrackList { // assume that everything is . This flag is useful when we encounter let mut at_least_one_not_fixed = false; loop { - current_names.extend_from_slice(&mut input.try(parse_line_names).unwrap_or_default()); - if let Ok(track_size) = input.try(|i| TrackSize::parse(context, i)) { + current_names + .extend_from_slice(&mut input.try_parse(parse_line_names).unwrap_or_default()); + if let Ok(track_size) = input.try_parse(|i| TrackSize::parse(context, i)) { if !track_size.is_fixed() { at_least_one_not_fixed = true; if auto_repeat_index.is_some() { @@ -238,7 +242,7 @@ impl Parse for TrackList { names.push(vec.into()); values.push(TrackListValue::TrackSize(track_size)); } else if let Ok((repeat, type_)) = - input.try(|i| TrackRepeat::parse_with_repeat_type(context, i)) + input.try_parse(|i| TrackRepeat::parse_with_repeat_type(context, i)) { match type_ { RepeatType::Normal => { @@ -312,7 +316,7 @@ impl Parse for GridTemplateComponent { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(GridTemplateComponent::None); } @@ -327,12 +331,15 @@ impl GridTemplateComponent { input: &mut Parser<'i, 't>, ) -> Result> { if allow_grid_template_subgrids() { - if let Ok(t) = input.try(|i| LineNameList::parse(context, i)) { + if let Ok(t) = input.try_parse(|i| LineNameList::parse(context, i)) { return Ok(GridTemplateComponent::Subgrid(Box::new(t))); } } if allow_grid_template_masonry() { - if input.try(|i| i.expect_ident_matching("masonry")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("masonry")) + .is_ok() + { return Ok(GridTemplateComponent::Masonry); } } diff --git a/components/style/values/specified/image.rs b/components/style/values/specified/image.rs index 59250c45a6f..088a4ace687 100644 --- a/components/style/values/specified/image.rs +++ b/components/style/values/specified/image.rs @@ -132,24 +132,24 @@ impl Parse for Image { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Image::None); } - if let Ok(url) = input.try(|input| SpecifiedImageUrl::parse(context, input)) { + if let Ok(url) = input.try_parse(|input| SpecifiedImageUrl::parse(context, input)) { return Ok(generic::Image::Url(url)); } - if let Ok(gradient) = input.try(|i| Gradient::parse(context, i)) { + if let Ok(gradient) = input.try_parse(|i| Gradient::parse(context, i)) { return Ok(generic::Image::Gradient(Box::new(gradient))); } #[cfg(feature = "servo-layout-2013")] { - if let Ok(paint_worklet) = input.try(|i| PaintWorklet::parse(context, i)) { + if let Ok(paint_worklet) = input.try_parse(|i| PaintWorklet::parse(context, i)) { return Ok(generic::Image::PaintWorklet(paint_worklet)); } } #[cfg(feature = "gecko")] { - if let Ok(image_rect) = input.try(|input| MozImageRect::parse(context, input)) { + if let Ok(image_rect) = input.try_parse(|input| MozImageRect::parse(context, input)) { return Ok(generic::Image::Rect(Box::new(image_rect))); } Ok(generic::Image::Element(Image::parse_element(input)?)) @@ -171,7 +171,7 @@ impl Image { /// Parses a `-moz-element(# )`. #[cfg(feature = "gecko")] fn parse_element<'i, 't>(input: &mut Parser<'i, 't>) -> Result> { - input.try(|i| i.expect_function_matching("-moz-element"))?; + input.try_parse(|i| i.expect_function_matching("-moz-element"))?; let location = input.current_source_location(); input.parse_nested_block(|i| match *i.next()? { Token::IDHash(ref id) => Ok(Atom::from(id.as_ref())), @@ -189,7 +189,7 @@ impl Image { input: &mut Parser<'i, 't>, ) -> Result> { if let Ok(url) = - input.try(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input)) + input.try_parse(|input| SpecifiedImageUrl::parse_with_cors_anonymous(context, input)) { return Ok(generic::Image::Url(url)); } @@ -332,7 +332,7 @@ impl Gradient { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - input.try(|i| { + input.try_parse(|i| { let x = Component::parse(context, i)?; let y = Component::parse(context, i)?; @@ -450,7 +450,7 @@ impl Gradient { reverse_stops: bool, ) -> Result> { let mut items = input - .try(|i| { + .try_parse(|i| { i.expect_comma()?; i.parse_comma_separated(|i| { let function = i.expect_function()?.clone(); @@ -551,18 +551,19 @@ impl Gradient { repeating: bool, mut compat_mode: GradientCompatMode, ) -> Result> { - let direction = - if let Ok(d) = input.try(|i| LineDirection::parse(context, i, &mut compat_mode)) { - input.expect_comma()?; - d - } else { - match compat_mode { - GradientCompatMode::Modern => { - LineDirection::Vertical(VerticalPositionKeyword::Bottom) - }, - _ => LineDirection::Vertical(VerticalPositionKeyword::Top), - } - }; + let direction = if let Ok(d) = + input.try_parse(|i| LineDirection::parse(context, i, &mut compat_mode)) + { + input.expect_comma()?; + d + } else { + match compat_mode { + GradientCompatMode::Modern => { + LineDirection::Vertical(VerticalPositionKeyword::Bottom) + }, + _ => LineDirection::Vertical(VerticalPositionKeyword::Top), + } + }; let items = Gradient::parse_stops(context, input)?; Ok(Gradient::Linear { @@ -582,16 +583,16 @@ impl Gradient { ) -> Result> { let (shape, position) = match compat_mode { GradientCompatMode::Modern => { - let shape = input.try(|i| EndingShape::parse(context, i, compat_mode)); - let position = input.try(|i| { + let shape = input.try_parse(|i| EndingShape::parse(context, i, compat_mode)); + let position = input.try_parse(|i| { i.expect_ident_matching("at")?; Position::parse(context, i) }); (shape, position.ok()) }, _ => { - let position = input.try(|i| Position::parse(context, i)); - let shape = input.try(|i| { + let position = input.try_parse(|i| Position::parse(context, i)); + let shape = input.try_parse(|i| { if position.is_ok() { i.expect_comma()?; } @@ -626,13 +627,13 @@ impl Gradient { input: &mut Parser<'i, 't>, repeating: bool, ) -> Result> { - let angle = input.try(|i| { + let angle = input.try_parse(|i| { i.expect_ident_matching("from")?; // Spec allows unitless zero start angles // https://drafts.csswg.org/css-images-4/#valdef-conic-gradient-angle Angle::parse_with_unitless(context, i) }); - let position = input.try(|i| { + let position = input.try_parse(|i| { i.expect_ident_matching("at")?; Position::parse(context, i) }); @@ -713,12 +714,12 @@ impl LineDirection { ) -> Result> { // Gradients allow unitless zero angles as an exception, see: // https://github.com/w3c/csswg-drafts/issues/1162 - if let Ok(angle) = input.try(|i| Angle::parse_with_unitless(context, i)) { + if let Ok(angle) = input.try_parse(|i| Angle::parse_with_unitless(context, i)) { return Ok(LineDirection::Angle(angle)); } - input.try(|i| { - let to_ident = i.try(|i| i.expect_ident_matching("to")); + input.try_parse(|i| { + let to_ident = i.try_parse(|i| i.expect_ident_matching("to")); match *compat_mode { // `to` keyword is mandatory in modern syntax. GradientCompatMode::Modern => to_ident?, @@ -738,14 +739,14 @@ impl LineDirection { _ => {}, } - if let Ok(x) = i.try(HorizontalPositionKeyword::parse) { - if let Ok(y) = i.try(VerticalPositionKeyword::parse) { + if let Ok(x) = i.try_parse(HorizontalPositionKeyword::parse) { + if let Ok(y) = i.try_parse(VerticalPositionKeyword::parse) { return Ok(LineDirection::Corner(x, y)); } return Ok(LineDirection::Horizontal(x)); } let y = VerticalPositionKeyword::parse(i)?; - if let Ok(x) = i.try(HorizontalPositionKeyword::parse) { + if let Ok(x) = i.try_parse(HorizontalPositionKeyword::parse) { return Ok(LineDirection::Corner(x, y)); } Ok(LineDirection::Vertical(y)) @@ -759,19 +760,28 @@ impl EndingShape { input: &mut Parser<'i, 't>, compat_mode: GradientCompatMode, ) -> Result> { - if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { - if input.try(|i| i.expect_ident_matching("circle")).is_ok() { + if let Ok(extent) = input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) + { + if input + .try_parse(|i| i.expect_ident_matching("circle")) + .is_ok() + { return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); } - let _ = input.try(|i| i.expect_ident_matching("ellipse")); + let _ = input.try_parse(|i| i.expect_ident_matching("ellipse")); return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); } - if input.try(|i| i.expect_ident_matching("circle")).is_ok() { - if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { + if input + .try_parse(|i| i.expect_ident_matching("circle")) + .is_ok() + { + if let Ok(extent) = + input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) + { return Ok(generic::EndingShape::Circle(Circle::Extent(extent))); } if compat_mode == GradientCompatMode::Modern { - if let Ok(length) = input.try(|i| NonNegativeLength::parse(context, i)) { + if let Ok(length) = input.try_parse(|i| NonNegativeLength::parse(context, i)) { return Ok(generic::EndingShape::Circle(Circle::Radius(length))); } } @@ -779,12 +789,17 @@ impl EndingShape { ShapeExtent::FarthestCorner, ))); } - if input.try(|i| i.expect_ident_matching("ellipse")).is_ok() { - if let Ok(extent) = input.try(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) { + if input + .try_parse(|i| i.expect_ident_matching("ellipse")) + .is_ok() + { + if let Ok(extent) = + input.try_parse(|i| ShapeExtent::parse_with_compat_mode(i, compat_mode)) + { return Ok(generic::EndingShape::Ellipse(Ellipse::Extent(extent))); } if compat_mode == GradientCompatMode::Modern { - let pair: Result<_, ParseError> = input.try(|i| { + let pair: Result<_, ParseError> = input.try_parse(|i| { let x = NonNegativeLengthPercentage::parse(context, i)?; let y = NonNegativeLengthPercentage::parse(context, i)?; Ok((x, y)) @@ -797,10 +812,10 @@ impl EndingShape { ShapeExtent::FarthestCorner, ))); } - if let Ok(length) = input.try(|i| NonNegativeLength::parse(context, i)) { - if let Ok(y) = input.try(|i| NonNegativeLengthPercentage::parse(context, i)) { + if let Ok(length) = input.try_parse(|i| NonNegativeLength::parse(context, i)) { + if let Ok(y) = input.try_parse(|i| NonNegativeLengthPercentage::parse(context, i)) { if compat_mode == GradientCompatMode::Modern { - let _ = input.try(|i| i.expect_ident_matching("ellipse")); + let _ = input.try_parse(|i| i.expect_ident_matching("ellipse")); } return Ok(generic::EndingShape::Ellipse(Ellipse::Radii( NonNegative(LengthPercentage::from(length.0)), @@ -808,7 +823,7 @@ impl EndingShape { ))); } if compat_mode == GradientCompatMode::Modern { - let y = input.try(|i| { + let y = input.try_parse(|i| { i.expect_ident_matching("ellipse")?; NonNegativeLengthPercentage::parse(context, i) }); @@ -818,16 +833,16 @@ impl EndingShape { y, ))); } - let _ = input.try(|i| i.expect_ident_matching("circle")); + let _ = input.try_parse(|i| i.expect_ident_matching("circle")); } return Ok(generic::EndingShape::Circle(Circle::Radius(length))); } - input.try(|i| { + input.try_parse(|i| { let x = Percentage::parse_non_negative(context, i)?; - let y = if let Ok(y) = i.try(|i| NonNegativeLengthPercentage::parse(context, i)) { + let y = if let Ok(y) = i.try_parse(|i| NonNegativeLengthPercentage::parse(context, i)) { if compat_mode == GradientCompatMode::Modern { - let _ = i.try(|i| i.expect_ident_matching("ellipse")); + let _ = i.try_parse(|i| i.expect_ident_matching("ellipse")); } y } else { @@ -875,7 +890,7 @@ impl generic::GradientItem { loop { input.parse_until_before(Delimiter::Comma, |input| { if seen_stop { - if let Ok(hint) = input.try(|i| parse_position(context, i)) { + if let Ok(hint) = input.try_parse(|i| parse_position(context, i)) { seen_stop = false; items.push(generic::GradientItem::InterpolationHint(hint)); return Ok(()); @@ -884,7 +899,7 @@ impl generic::GradientItem { let stop = generic::ColorStop::parse(context, input, parse_position)?; - if let Ok(multi_position) = input.try(|i| parse_position(context, i)) { + if let Ok(multi_position) = input.try_parse(|i| parse_position(context, i)) { let stop_color = stop.color.clone(); items.push(stop.into_item()); items.push( @@ -927,7 +942,7 @@ impl generic::ColorStop { ) -> Result> { Ok(generic::ColorStop { color: Color::parse(context, input)?, - position: input.try(|i| parse_position(context, i)).ok(), + position: input.try_parse(|i| parse_position(context, i)).ok(), }) } } @@ -941,7 +956,7 @@ impl Parse for PaintWorklet { input.parse_nested_block(|input| { let name = Atom::from(&**input.expect_ident()?); let arguments = input - .try(|input| { + .try_parse(|input| { input.expect_comma()?; input.parse_comma_separated(|input| SpecifiedValue::parse(input)) }) @@ -965,7 +980,7 @@ impl Parse for MozImageRect { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - input.try(|i| i.expect_function_matching("-moz-image-rect"))?; + input.try_parse(|i| i.expect_function_matching("-moz-image-rect"))?; input.parse_nested_block(|i| { let string = i.expect_url_or_string()?; let url = SpecifiedImageUrl::parse_from_string( diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 0b1bf0b68a7..bf81a4d5e3d 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -1226,12 +1226,12 @@ impl Size { ) -> Result> { #[cfg(feature = "gecko")] { - if let Ok(l) = input.try(computed::ExtremumLength::parse) { + if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) { return Ok(GenericSize::ExtremumLength(l)); } } - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(GenericSize::Auto); } @@ -1267,12 +1267,12 @@ impl MaxSize { ) -> Result> { #[cfg(feature = "gecko")] { - if let Ok(l) = input.try(computed::ExtremumLength::parse) { + if let Ok(l) = input.try_parse(computed::ExtremumLength::parse) { return Ok(GenericMaxSize::ExtremumLength(l)); } } - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(GenericMaxSize::None); } diff --git a/components/style/values/specified/list.rs b/components/style/values/specified/list.rs index 1c93f8e8a58..5d31c0b34d2 100644 --- a/components/style/values/specified/list.rs +++ b/components/style/values/specified/list.rs @@ -75,10 +75,10 @@ impl Parse for ListStyleType { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(style) = input.try(|i| CounterStyle::parse(context, i)) { + if let Ok(style) = input.try_parse(|i| CounterStyle::parse(context, i)) { return Ok(ListStyleType::CounterStyle(style)); } - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(ListStyleType::None); } Ok(ListStyleType::String( @@ -155,14 +155,14 @@ impl Parse for Quotes { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("auto")) + .try_parse(|input| input.expect_ident_matching("auto")) .is_ok() { return Ok(Quotes::Auto); } if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(Quotes::QuoteList(QuoteList::default())); diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 9d90ffab1b0..8ddca48d599 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -50,7 +50,7 @@ pub use self::effects::{BoxShadow, Filter, SimpleShadow}; pub use self::flex::FlexBasis; pub use self::font::{FontFamily, FontLanguageOverride, FontStyle}; pub use self::font::{FontFeatureSettings, FontVariantLigatures, FontVariantNumeric}; -pub use self::font::{FontSize, FontSizeAdjust, FontStretch, FontSynthesis, FontSizeKeyword}; +pub use self::font::{FontSize, FontSizeAdjust, FontSizeKeyword, FontStretch, FontSynthesis}; pub use self::font::{FontVariantAlternates, FontWeight}; pub use self::font::{FontVariantEastAsian, FontVariationSettings}; pub use self::font::{MozScriptLevel, MozScriptMinSize, MozScriptSizeMultiplier, XLang, XTextZoom}; @@ -148,7 +148,7 @@ impl AngleOrPercentage { input: &mut Parser<'i, 't>, allow_unitless_zero: AllowUnitlessZeroAngle, ) -> Result> { - if let Ok(per) = input.try(|i| Percentage::parse(context, i)) { + if let Ok(per) = input.try_parse(|i| Percentage::parse(context, i)) { return Ok(AngleOrPercentage::Percentage(per)); } @@ -431,7 +431,9 @@ impl NumberOrPercentage { input: &mut Parser<'i, 't>, type_: AllowedNumericType, ) -> Result> { - if let Ok(per) = input.try(|i| Percentage::parse_with_clamping_mode(context, i, type_)) { + if let Ok(per) = + input.try_parse(|i| Percentage::parse_with_clamping_mode(context, i, type_)) + { return Ok(NumberOrPercentage::Percentage(per)); } @@ -750,7 +752,7 @@ impl ClipRect { let bottom; let left; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { right = parse_argument(context, input, allow_quirks)?; input.expect_comma()?; bottom = parse_argument(context, input, allow_quirks)?; @@ -782,7 +784,7 @@ impl ClipRectOrAuto { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if let Ok(v) = input.try(|i| ClipRect::parse_quirky(context, i, allow_quirks)) { + if let Ok(v) = input.try_parse(|i| ClipRect::parse_quirky(context, i, allow_quirks)) { return Ok(generics::GenericClipRectOrAuto::Rect(v)); } input.expect_ident_matching("auto")?; @@ -866,8 +868,8 @@ impl Attr { ) -> Result> { // Syntax is `[namespace? `|`]? ident` // no spaces allowed - let first = input.try(|i| i.expect_ident_cloned()).ok(); - if let Ok(token) = input.try(|i| i.next_including_whitespace().map(|t| t.clone())) { + let first = input.try_parse(|i| i.expect_ident_cloned()).ok(); + if let Ok(token) = input.try_parse(|i| i.next_including_whitespace().map(|t| t.clone())) { match token { Token::Delim('|') => { let location = input.current_source_location(); diff --git a/components/style/values/specified/motion.rs b/components/style/values/specified/motion.rs index 2351acecc6a..7831b78afe6 100644 --- a/components/style/values/specified/motion.rs +++ b/components/style/values/specified/motion.rs @@ -39,18 +39,20 @@ impl Parse for RayFunction { let mut contain = false; loop { if angle.is_none() { - angle = input.try(|i| Angle::parse(context, i)).ok(); + angle = input.try_parse(|i| Angle::parse(context, i)).ok(); } if size.is_none() { - size = input.try(RaySize::parse).ok(); + size = input.try_parse(RaySize::parse).ok(); if size.is_some() { continue; } } if !contain { - contain = input.try(|i| i.expect_ident_matching("contain")).is_ok(); + contain = input + .try_parse(|i| i.expect_ident_matching("contain")) + .is_ok(); if contain { continue; } @@ -76,7 +78,7 @@ impl Parse for OffsetPath { input: &mut Parser<'i, 't>, ) -> Result> { // Parse none. - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(OffsetPath::none()); } @@ -166,12 +168,12 @@ impl Parse for OffsetRotate { input: &mut Parser<'i, 't>, ) -> Result> { let location = input.current_source_location(); - let mut direction = input.try(OffsetRotateDirection::parse); - let angle = input.try(|i| Angle::parse(context, i)); + let mut direction = input.try_parse(OffsetRotateDirection::parse); + let angle = input.try_parse(|i| Angle::parse(context, i)); if direction.is_err() { // The direction and angle could be any order, so give it a change to parse // direction again. - direction = input.try(OffsetRotateDirection::parse); + direction = input.try_parse(OffsetRotateDirection::parse); } if direction.is_err() && angle.is_err() { diff --git a/components/style/values/specified/outline.rs b/components/style/values/specified/outline.rs index b981d8068e7..6e5382d4c2b 100644 --- a/components/style/values/specified/outline.rs +++ b/components/style/values/specified/outline.rs @@ -56,7 +56,7 @@ impl Parse for OutlineStyle { _context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(border_style) = input.try(BorderStyle::parse) { + if let Ok(border_style) = input.try_parse(BorderStyle::parse) { if let BorderStyle::Hidden = border_style { return Err(input .new_custom_error(SelectorParseErrorKind::UnexpectedIdent("hidden".into()))); diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index c2998de328b..72886b2d7b1 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -116,28 +116,31 @@ impl Position { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - match input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) { + match input.try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) { Ok(x_pos @ PositionComponent::Center) => { if let Ok(y_pos) = - input.try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) + input.try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) { return Ok(Self::new(x_pos, y_pos)); } let x_pos = input - .try(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| PositionComponent::parse_quirky(context, i, allow_quirks)) .unwrap_or(x_pos); let y_pos = PositionComponent::Center; return Ok(Self::new(x_pos, y_pos)); }, Ok(PositionComponent::Side(x_keyword, lp)) => { - if input.try(|i| i.expect_ident_matching("center")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("center")) + .is_ok() + { let x_pos = PositionComponent::Side(x_keyword, lp); let y_pos = PositionComponent::Center; return Ok(Self::new(x_pos, y_pos)); } - if let Ok(y_keyword) = input.try(VerticalPositionKeyword::parse) { + if let Ok(y_keyword) = input.try_parse(VerticalPositionKeyword::parse) { let y_lp = input - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); let x_pos = PositionComponent::Side(x_keyword, lp); let y_pos = PositionComponent::Side(y_keyword, y_lp); @@ -148,30 +151,30 @@ impl Position { return Ok(Self::new(x_pos, y_pos)); }, Ok(x_pos @ PositionComponent::Length(_)) => { - if let Ok(y_keyword) = input.try(VerticalPositionKeyword::parse) { + if let Ok(y_keyword) = input.try_parse(VerticalPositionKeyword::parse) { let y_pos = PositionComponent::Side(y_keyword, None); return Ok(Self::new(x_pos, y_pos)); } if let Ok(y_lp) = - input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) { let y_pos = PositionComponent::Length(y_lp); return Ok(Self::new(x_pos, y_pos)); } let y_pos = PositionComponent::Center; - let _ = input.try(|i| i.expect_ident_matching("center")); + let _ = input.try_parse(|i| i.expect_ident_matching("center")); return Ok(Self::new(x_pos, y_pos)); }, Err(_) => {}, } let y_keyword = VerticalPositionKeyword::parse(input)?; - let lp_and_x_pos: Result<_, ParseError> = input.try(|i| { + let lp_and_x_pos: Result<_, ParseError> = input.try_parse(|i| { let y_lp = i - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); - if let Ok(x_keyword) = i.try(HorizontalPositionKeyword::parse) { + if let Ok(x_keyword) = i.try_parse(HorizontalPositionKeyword::parse) { let x_lp = i - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); let x_pos = PositionComponent::Side(x_keyword, x_lp); return Ok((y_lp, x_pos)); @@ -250,15 +253,20 @@ impl PositionComponent { input: &mut Parser<'i, 't>, allow_quirks: AllowQuirks, ) -> Result> { - if input.try(|i| i.expect_ident_matching("center")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("center")) + .is_ok() + { return Ok(PositionComponent::Center); } - if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) { + if let Ok(lp) = + input.try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + { return Ok(PositionComponent::Length(lp)); } let keyword = S::parse(context, input)?; let lp = input - .try(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) + .try_parse(|i| LengthPercentage::parse_quirky(context, i, allow_quirks)) .ok(); Ok(PositionComponent::Side(keyword, lp)) } @@ -730,7 +738,7 @@ impl Parse for TemplateAreas { ) -> Result> { let mut strings = vec![]; while let Ok(string) = - input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) + input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned().into())) { strings.push(string); } @@ -889,10 +897,10 @@ impl Parse for AspectRatio { use crate::values::generics::position::PreferredRatio; let location = input.current_source_location(); - let mut auto = input.try(|i| i.expect_ident_matching("auto")); - let ratio = input.try(|i| Ratio::parse(context, i)); + let mut auto = input.try_parse(|i| i.expect_ident_matching("auto")); + let ratio = input.try_parse(|i| Ratio::parse(context, i)); if auto.is_err() { - auto = input.try(|i| i.expect_ident_matching("auto")); + auto = input.try_parse(|i| i.expect_ident_matching("auto")); } if auto.is_err() && ratio.is_err() { diff --git a/components/style/values/specified/source_size_list.rs b/components/style/values/specified/source_size_list.rs index 3cb558809ad..edb2c09f73e 100644 --- a/components/style/values/specified/source_size_list.rs +++ b/components/style/values/specified/source_size_list.rs @@ -87,7 +87,7 @@ impl Parse for SourceSizeOrLength { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(size) = input.try(|input| SourceSize::parse(context, input)) { + if let Ok(size) = input.try_parse(|input| SourceSize::parse(context, input)) { return Ok(SourceSizeOrLength::SourceSize(size)); } diff --git a/components/style/values/specified/svg.rs b/components/style/values/specified/svg.rs index cff899fce35..abc6587239c 100644 --- a/components/style/values/specified/svg.rs +++ b/components/style/values/specified/svg.rs @@ -48,7 +48,8 @@ macro_rules! parse_svg_length { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(lp) = input.try(|i| <$lp>::parse_quirky(context, i, AllowQuirks::Always)) + if let Ok(lp) = + input.try_parse(|i| <$lp>::parse_quirky(context, i, AllowQuirks::Always)) { return Ok(generic::SVGLength::LengthPercentage(lp)); } @@ -71,7 +72,7 @@ impl Parse for SVGStrokeDashArray { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(values) = input.try(|i| { + if let Ok(values) = input.try_parse(|i| { CommaWithSpace::parse(i, |i| { NonNegativeLengthPercentage::parse_quirky(context, i, AllowQuirks::Always) }) @@ -161,7 +162,7 @@ impl Parse for SVGPaintOrder { _context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if let Ok(()) = input.try(|i| i.expect_ident_matching("normal")) { + if let Ok(()) = input.try_parse(|i| i.expect_ident_matching("normal")) { return Ok(SVGPaintOrder::normal()); } @@ -172,7 +173,7 @@ impl Parse for SVGPaintOrder { let mut pos = 0; loop { - let result: Result<_, ParseError> = input.try(|input| { + let result: Result<_, ParseError> = input.try_parse(|input| { try_match_ident_ignore_ascii_case! { input, "fill" => Ok(PaintOrder::Fill), "stroke" => Ok(PaintOrder::Stroke), diff --git a/components/style/values/specified/text.rs b/components/style/values/specified/text.rs index bee3c665840..7c5c712eb3e 100644 --- a/components/style/values/specified/text.rs +++ b/components/style/values/specified/text.rs @@ -41,11 +41,16 @@ impl Parse for InitialLetter { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("normal")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("normal")) + .is_ok() + { return Ok(GenericInitialLetter::Normal); } let size = Number::parse_at_least_one(context, input)?; - let sink = input.try(|i| Integer::parse_positive(context, i)).ok(); + let sink = input + .try_parse(|i| Integer::parse_positive(context, i)) + .ok(); Ok(GenericInitialLetter::Specified(size, sink)) } } @@ -161,7 +166,7 @@ impl Parse for TextOverflow { ) -> Result> { let first = TextOverflowSide::parse(context, input)?; let second = input - .try(|input| TextOverflowSide::parse(context, input)) + .try_parse(|input| TextOverflowSide::parse(context, input)) .ok(); Ok(TextOverflow { first, second }) } @@ -251,7 +256,7 @@ impl Parse for TextDecorationLine { // ensure we don't return an error if we don't consume the whole thing // because we find an invalid identifier or other kind of token. loop { - let flag: Result<_, ParseError<'i>> = input.try(|input| { + let flag: Result<_, ParseError<'i>> = input.try_parse(|input| { let flag = try_match_ident_ignore_ascii_case! { input, "none" if result.is_empty() => TextDecorationLine::NONE, "underline" => TextDecorationLine::UNDERLINE, @@ -791,22 +796,22 @@ impl Parse for TextEmphasisStyle { input: &mut Parser<'i, 't>, ) -> Result> { if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(TextEmphasisStyle::None); } - if let Ok(s) = input.try(|i| i.expect_string().map(|s| s.as_ref().to_owned())) { + if let Ok(s) = input.try_parse(|i| i.expect_string().map(|s| s.as_ref().to_owned())) { // Handle return Ok(TextEmphasisStyle::String(s.into())); } // Handle a pair of keywords - let mut shape = input.try(TextEmphasisShapeKeyword::parse).ok(); - let fill = input.try(TextEmphasisFillMode::parse).ok(); + let mut shape = input.try_parse(TextEmphasisShapeKeyword::parse).ok(); + let fill = input.try_parse(TextEmphasisFillMode::parse).ok(); if shape.is_none() { - shape = input.try(TextEmphasisShapeKeyword::parse).ok(); + shape = input.try_parse(TextEmphasisShapeKeyword::parse).ok(); } if shape.is_none() && fill.is_none() { @@ -922,7 +927,7 @@ impl Parse for TextEmphasisPosition { input: &mut Parser<'i, 't>, ) -> Result> { if let Ok(horizontal) = - input.try(|input| TextEmphasisHorizontalWritingModeValue::parse(input)) + input.try_parse(|input| TextEmphasisHorizontalWritingModeValue::parse(input)) { let vertical = TextEmphasisVerticalWritingModeValue::parse(input)?; Ok(TextEmphasisPosition(horizontal, vertical)) diff --git a/components/style/values/specified/transform.rs b/components/style/values/specified/transform.rs index a61f982cd2d..ba2be4ee8d3 100644 --- a/components/style/values/specified/transform.rs +++ b/components/style/values/specified/transform.rs @@ -68,7 +68,7 @@ impl Transform { use style_traits::{Separator, Space}; if input - .try(|input| input.expect_ident_matching("none")) + .try_parse(|input| input.expect_ident_matching("none")) .is_ok() { return Ok(generic::Transform::none()); @@ -137,7 +137,7 @@ impl Transform { }, "translate" => { let sx = specified::LengthPercentage::parse(context, input)?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { let sy = specified::LengthPercentage::parse(context, input)?; Ok(generic::TransformOperation::Translate(sx, sy)) } else { @@ -166,7 +166,7 @@ impl Transform { }, "scale" => { let sx = NumberOrPercentage::parse(context, input)?.to_number(); - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { let sy = NumberOrPercentage::parse(context, input)?.to_number(); Ok(generic::TransformOperation::Scale(sx, sy)) } else { @@ -222,7 +222,7 @@ impl Transform { }, "skew" => { let ax = specified::Angle::parse_with_unitless(context, input)?; - if input.try(|input| input.expect_comma()).is_ok() { + if input.try_parse(|input| input.expect_comma()).is_ok() { let ay = specified::Angle::parse_with_unitless(context, input)?; Ok(generic::TransformOperation::Skew(ax, ay)) } else { @@ -282,17 +282,17 @@ impl Parse for TransformOrigin { ) -> Result> { let parse_depth = |input: &mut Parser| { input - .try(|i| Length::parse(context, i)) + .try_parse(|i| Length::parse(context, i)) .unwrap_or(Length::zero()) }; - match input.try(|i| OriginComponent::parse(context, i)) { + match input.try_parse(|i| OriginComponent::parse(context, i)) { Ok(x_origin @ OriginComponent::Center) => { - if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) { + if let Ok(y_origin) = input.try_parse(|i| OriginComponent::parse(context, i)) { let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); } let y_origin = OriginComponent::Center; - if let Ok(x_keyword) = input.try(HorizontalPositionKeyword::parse) { + if let Ok(x_keyword) = input.try_parse(HorizontalPositionKeyword::parse) { let x_origin = OriginComponent::Side(x_keyword); let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); @@ -301,7 +301,7 @@ impl Parse for TransformOrigin { return Ok(Self::new(x_origin, y_origin, depth)); }, Ok(x_origin) => { - if let Ok(y_origin) = input.try(|i| OriginComponent::parse(context, i)) { + if let Ok(y_origin) = input.try_parse(|i| OriginComponent::parse(context, i)) { let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); } @@ -313,12 +313,15 @@ impl Parse for TransformOrigin { } let y_keyword = VerticalPositionKeyword::parse(input)?; let y_origin = OriginComponent::Side(y_keyword); - if let Ok(x_keyword) = input.try(HorizontalPositionKeyword::parse) { + if let Ok(x_keyword) = input.try_parse(HorizontalPositionKeyword::parse) { let x_origin = OriginComponent::Side(x_keyword); let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); } - if input.try(|i| i.expect_ident_matching("center")).is_ok() { + if input + .try_parse(|i| i.expect_ident_matching("center")) + .is_ok() + { let x_origin = OriginComponent::Center; let depth = parse_depth(input); return Ok(Self::new(x_origin, y_origin, depth)); @@ -368,7 +371,7 @@ impl Parse for Rotate { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Rotate::None); } @@ -376,9 +379,11 @@ impl Parse for Rotate { // // The rotate axis and angle could be in any order, so we parse angle twice to cover // two cases. i.e. `{3} ` or ` {3}` - let angle = input.try(|i| specified::Angle::parse(context, i)).ok(); + let angle = input + .try_parse(|i| specified::Angle::parse(context, i)) + .ok(); let axis = input - .try(|i| { + .try_parse(|i| { Ok(try_match_ident_ignore_ascii_case! { i, "x" => (Number::new(1.), Number::new(0.), Number::new(0.)), "y" => (Number::new(0.), Number::new(1.), Number::new(0.)), @@ -386,7 +391,7 @@ impl Parse for Rotate { }) }) .or_else(|_: ParseError| -> Result<_, ParseError> { - input.try(|i| { + input.try_parse(|i| { Ok(( Number::parse(context, i)?, Number::parse(context, i)?, @@ -415,13 +420,13 @@ impl Parse for Translate { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Translate::None); } let tx = specified::LengthPercentage::parse(context, input)?; - if let Ok(ty) = input.try(|i| specified::LengthPercentage::parse(context, i)) { - if let Ok(tz) = input.try(|i| specified::Length::parse(context, i)) { + if let Ok(ty) = input.try_parse(|i| specified::LengthPercentage::parse(context, i)) { + if let Ok(tz) = input.try_parse(|i| specified::Length::parse(context, i)) { // 'translate: ' return Ok(generic::Translate::Translate(tx, ty, tz)); } @@ -454,14 +459,14 @@ impl Parse for Scale { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("none")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() { return Ok(generic::Scale::None); } let sx = NumberOrPercentage::parse(context, input)?.to_number(); - if let Ok(sy) = input.try(|i| NumberOrPercentage::parse(context, i)) { + if let Ok(sy) = input.try_parse(|i| NumberOrPercentage::parse(context, i)) { let sy = sy.to_number(); - if let Ok(sz) = input.try(|i| NumberOrPercentage::parse(context, i)) { + if let Ok(sz) = input.try_parse(|i| NumberOrPercentage::parse(context, i)) { // 'scale: ' return Ok(generic::Scale::Scale(sx, sy, sz.to_number())); } diff --git a/components/style/values/specified/ui.rs b/components/style/values/specified/ui.rs index b94267162c9..74440a67205 100644 --- a/components/style/values/specified/ui.rs +++ b/components/style/values/specified/ui.rs @@ -27,7 +27,7 @@ impl Parse for Cursor { ) -> Result> { let mut images = vec![]; loop { - match input.try(|input| CursorImage::parse(context, input)) { + match input.try_parse(|input| CursorImage::parse(context, input)) { Ok(image) => images.push(image), Err(_) => break, } @@ -52,7 +52,7 @@ impl Parse for CursorImage { let mut hotspot_x = Number::zero(); let mut hotspot_y = Number::zero(); - if let Ok(x) = input.try(|input| Number::parse(context, input)) { + if let Ok(x) = input.try_parse(|input| Number::parse(context, input)) { has_hotspot = true; hotspot_x = x; hotspot_y = Number::parse(context, input)?; @@ -136,7 +136,7 @@ impl Parse for ScrollbarColor { context: &ParserContext, input: &mut Parser<'i, 't>, ) -> Result> { - if input.try(|i| i.expect_ident_matching("auto")).is_ok() { + if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() { return Ok(generics::ScrollbarColor::Auto); } Ok(generics::ScrollbarColor::Colors { From 3884328ce329118ded269fc906604498252a75c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Fri, 5 Jun 2020 18:13:14 +0000 Subject: [PATCH 03/17] style: Clear last_parsed_property_id right after successfully parsing the value. Rather than waiting until parsing another id (successfully or unsuccessfully). If we error before we even get to PropertyId::parse, we'd incorrectly associate the error with the wrong property, incorrectly omitting it sometimes. Differential Revision: https://phabricator.services.mozilla.com/D78260 --- components/style/properties/declaration_block.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 5dc5d207f36..75d05836972 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -1347,7 +1347,6 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for PropertyDeclarationParser<'a, 'b> { let id = match PropertyId::parse(&name, self.context) { Ok(id) => id, Err(..) => { - self.last_parsed_property_id = None; return Err(input.new_custom_error(StyleParseErrorKind::UnknownProperty(name))); }, }; @@ -1469,6 +1468,10 @@ pub fn parse_property_declaration_list( match declaration { Ok(importance) => { block.extend(iter.parser.declarations.drain(), importance); + // We've successfully parsed a declaration, so forget about + // `last_parsed_property_id`. It'd be wrong to associate any + // following error with this property. + iter.parser.last_parsed_property_id = None; }, Err((error, slice)) => { iter.parser.declarations.clear(); From c578a82adca15b3e4d859cd198167021627cc917 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 17 Jun 2020 22:27:45 +0000 Subject: [PATCH 04/17] style: Fix some manual occurrences of try(). Depends on D80099 Differential Revision: https://phabricator.services.mozilla.com/D80100 --- components/style/values/specified/effects.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/components/style/values/specified/effects.rs b/components/style/values/specified/effects.rs index 87578b127e6..fd92e6ee95e 100644 --- a/components/style/values/specified/effects.rs +++ b/components/style/values/specified/effects.rs @@ -149,18 +149,17 @@ impl Parse for BoxShadow { } } if lengths.is_none() { - let value = input.try::<_, _, ParseError>(|i| { + let value = input.try_parse::<_, _, ParseError>(|i| { let horizontal = Length::parse(context, i)?; let vertical = Length::parse(context, i)?; - let (blur, spread) = match i - .try::<_, _, ParseError>(|i| Length::parse_non_negative(context, i)) - { - Ok(blur) => { - let spread = i.try_parse(|i| Length::parse(context, i)).ok(); - (Some(blur.into()), spread) - }, - Err(_) => (None, None), - }; + let (blur, spread) = + match i.try_parse(|i| Length::parse_non_negative(context, i)) { + Ok(blur) => { + let spread = i.try_parse(|i| Length::parse(context, i)).ok(); + (Some(blur.into()), spread) + }, + Err(_) => (None, None), + }; Ok((horizontal, vertical, blur, spread)) }); if let Ok(value) = value { From 9b980e2f491293b921b3feec7bce4965e410890c Mon Sep 17 00:00:00 2001 From: Cameron McCormack Date: Fri, 5 Jun 2020 00:39:50 +0000 Subject: [PATCH 05/17] style: Add telemetry for -moz-appearance usage. Differential Revision: https://phabricator.services.mozilla.com/D77637 --- components/style/properties/declaration_block.rs | 15 +++++++++++++++ components/style/properties/longhands/box.mako.rs | 15 +++++++++++++++ components/style/properties/properties.mako.rs | 3 ++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 75d05836972..2bb7a8c7442 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -348,6 +348,21 @@ impl PropertyDeclarationBlock { .find(|(declaration, _)| declaration.id() == property) } + /// Get a declaration for a given property with the specified importance. + #[inline] + pub fn get_at_importance( + &self, + property: PropertyDeclarationId, + importance: Importance, + ) -> Option<&PropertyDeclaration> { + let (declaration, i) = self.get(property)?; + if i == importance { + Some(declaration) + } else { + None + } + } + /// Tries to serialize a given shorthand from the declarations in this /// block. pub fn shorthand_to_css( diff --git a/components/style/properties/longhands/box.mako.rs b/components/style/properties/longhands/box.mako.rs index 53aaf453d92..943bd0f27ff 100644 --- a/components/style/properties/longhands/box.mako.rs +++ b/components/style/properties/longhands/box.mako.rs @@ -627,6 +627,21 @@ ${helpers.predefined_type( gecko_ffi_name="mAppearance", )} +// A UA-sheet only property that is always set to the same value as +// -moz-appearance. Used to record telemetry for when author sheets +// override the value of -moz-appearance; see +// nsIFrame::RecordAppearanceTelemetry. +${helpers.predefined_type( + "-moz-default-appearance", + "Appearance", + "computed::Appearance::None", + engines="gecko", + animation_value_type="none", + spec="Internal (not web-exposed)", + enabled_in="ua", + gecko_ffi_name="mDefaultAppearance", +)} + ${helpers.single_keyword( "-moz-orient", "inline block horizontal vertical", diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index 12904fe1ca4..e0e0fe4cb03 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -2111,7 +2111,8 @@ impl PropertyId { pub struct WideKeywordDeclaration { #[css(skip)] id: LonghandId, - keyword: CSSWideKeyword, + /// The CSS-wide keyword. + pub keyword: CSSWideKeyword, } /// An unparsed declaration that contains `var()` functions. From 8f215a844464139d7341bc3977971260cf7f5886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 17 Jun 2020 23:40:30 +0000 Subject: [PATCH 06/17] style: Port the style crate to rust 2018. Differential Revision: https://phabricator.services.mozilla.com/D80101 --- components/style/Cargo.toml | 1 + components/style/build_gecko.rs | 2 +- components/style/dom.rs | 2 +- components/style/gecko_bindings/sugar/ownership.rs | 2 +- components/style/matching.rs | 9 ++++++--- .../properties/helpers/animated_properties.mako.rs | 2 +- components/style/values/computed/length.rs | 10 +++++----- components/style/values/generics/image.rs | 2 +- components/style/values/generics/ui.rs | 2 +- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 956a2c3f3d7..4baf6d381ef 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -6,6 +6,7 @@ license = "MPL-2.0" publish = false build = "build.rs" +edition = "2018" # https://github.com/rust-lang/cargo/issues/3544 links = "servo_style_crate" diff --git a/components/style/build_gecko.rs b/components/style/build_gecko.rs index dfd2a213d99..1e93660936a 100644 --- a/components/style/build_gecko.rs +++ b/components/style/build_gecko.rs @@ -318,7 +318,7 @@ fn generate_structs() { fixups.push(Fixup { pat: format!("\\broot\\s*::\\s*{}\\b", gecko), - rep: format!("::gecko_bindings::structs::{}", gecko_name), + rep: format!("crate::gecko_bindings::structs::{}", gecko_name), }); builder.blacklist_type(gecko).raw_line(format!( "pub type {0}{2} = {1}{2};", diff --git a/components/style/dom.rs b/components/style/dom.rs index 9c4ebd28d1e..a61739b920e 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -816,7 +816,7 @@ pub trait TElement: Self: 'a, F: FnMut(&'a CascadeData, Self), { - use rule_collector::containing_shadow_ignoring_svg_use; + use crate::rule_collector::containing_shadow_ignoring_svg_use; let target = self.rule_hash_target(); if !target.matches_user_and_author_rules() { diff --git a/components/style/gecko_bindings/sugar/ownership.rs b/components/style/gecko_bindings/sugar/ownership.rs index 366e4619c68..249134169f5 100644 --- a/components/style/gecko_bindings/sugar/ownership.rs +++ b/components/style/gecko_bindings/sugar/ownership.rs @@ -4,7 +4,7 @@ //! Helpers for different FFI pointer kinds that Gecko's FFI layer uses. -use gecko_bindings::structs::root::mozilla::detail::CopyablePtr; +use crate::gecko_bindings::structs::root::mozilla::detail::CopyablePtr; use servo_arc::{Arc, RawOffsetArc}; use std::marker::PhantomData; use std::mem::{forget, transmute}; diff --git a/components/style/matching.rs b/components/style/matching.rs index 95742c68f4a..31ba54a37e0 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -371,7 +371,7 @@ trait PrivateMatchMethods: TElement { // since we have no way to know whether the decendants // need to be traversed at the beginning of the animation-only // restyle). - let task = ::context::SequentialTask::process_post_animation( + let task = crate::context::SequentialTask::process_post_animation( *self, PostAnimationTasks::DISPLAY_CHANGED_FROM_NONE_FOR_SMIL, ); @@ -464,8 +464,11 @@ trait PrivateMatchMethods: TElement { } if !tasks.is_empty() { - let task = - ::context::SequentialTask::update_animations(*self, before_change_style, tasks); + let task = crate::context::SequentialTask::update_animations( + *self, + before_change_style, + tasks, + ); context.thread_local.tasks.push(task); } } diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index f0c9c7cad78..304f026deda 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -35,7 +35,7 @@ use void::{self, Void}; #[allow(non_upper_case_globals)] impl From for TransitionProperty { fn from(property: nsCSSPropertyID) -> TransitionProperty { - use properties::ShorthandId; + use crate::properties::ShorthandId; match property { % for prop in data.longhands: ${prop.nscsspropertyid()} => { diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 8c6dde8c738..61b8148bb65 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -87,7 +87,7 @@ macro_rules! computed_length_percentage_or_auto { /// Returns true if the computed value is absolute 0 or 0%. #[inline] pub fn is_definitely_zero(&self) -> bool { - use values::generics::length::LengthPercentageOrAuto::*; + use crate::values::generics::length::LengthPercentageOrAuto::*; match *self { LengthPercentage(ref l) => l.is_definitely_zero(), Auto => false, @@ -102,7 +102,7 @@ pub type LengthPercentageOrAuto = generics::GenericLengthPercentageOrAuto Self { - use values::generics::length::LengthPercentageOrAuto::*; + use crate::values::generics::length::LengthPercentageOrAuto::*; match self { LengthPercentage(l) => LengthPercentage(l.clamp_to_non_negative()), Auto => Auto, @@ -111,7 +111,7 @@ impl LengthPercentageOrAuto { /// Convert to have a borrow inside the enum pub fn as_ref(&self) -> generics::GenericLengthPercentageOrAuto<&LengthPercentage> { - use values::generics::length::LengthPercentageOrAuto::*; + use crate::values::generics::length::LengthPercentageOrAuto::*; match *self { LengthPercentage(ref lp) => LengthPercentage(lp), Auto => Auto, @@ -125,7 +125,7 @@ impl generics::GenericLengthPercentageOrAuto<&LengthPercentage> { /// Resolves the percentage. #[inline] pub fn percentage_relative_to(&self, basis: Length) -> LengthOrAuto { - use values::generics::length::LengthPercentageOrAuto::*; + use crate::values::generics::length::LengthPercentageOrAuto::*; match self { LengthPercentage(length_percentage) => { LengthPercentage(length_percentage.percentage_relative_to(basis)) @@ -137,7 +137,7 @@ impl generics::GenericLengthPercentageOrAuto<&LengthPercentage> { /// Maybe resolves the percentage. #[inline] pub fn maybe_percentage_relative_to(&self, basis: Option) -> LengthOrAuto { - use values::generics::length::LengthPercentageOrAuto::*; + use crate::values::generics::length::LengthPercentageOrAuto::*; match self { LengthPercentage(length_percentage) => length_percentage .maybe_percentage_relative_to(basis) diff --git a/components/style/values/generics/image.rs b/components/style/values/generics/image.rs index 42d541dc6f2..fba1f3f3c78 100644 --- a/components/style/values/generics/image.rs +++ b/components/style/values/generics/image.rs @@ -7,13 +7,13 @@ //! [images]: https://drafts.csswg.org/css-images/#image-values use crate::custom_properties; +use crate::values::generics::position::PositionComponent; use crate::values::serialize_atom_identifier; use crate::Atom; use crate::Zero; use servo_arc::Arc; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; -use values::generics::position::PositionComponent; /// An ` | none` value. /// diff --git a/components/style/values/generics/ui.rs b/components/style/values/generics/ui.rs index 6dfbb4a9c94..04c2951c70b 100644 --- a/components/style/values/generics/ui.rs +++ b/components/style/values/generics/ui.rs @@ -4,9 +4,9 @@ //! Generic values for UI properties. +use crate::values::specified::ui::CursorKind; use std::fmt::{self, Write}; use style_traits::{CssWriter, ToCss}; -use values::specified::ui::CursorKind; /// A generic value for the `cursor` property. /// From af2e157c8889ed5f13e072d1f75708a4d40363b9 Mon Sep 17 00:00:00 2001 From: Colomban Wendling Date: Wed, 3 Jun 2020 20:52:55 +0000 Subject: [PATCH 07/17] style: Fix tree column header color to follow theme. The background color for the tree column headers is drawn using the system APIs, but the foreground uses custom colors, which didn't follow theme. This can lead to unreadable text with specific colors, e.g. leading to black on black. Fix this by using system colors for the foreground as well. It also adds on-hover styling to match possible background change on hover. Differential Revision: https://phabricator.services.mozilla.com/D78073 --- components/style/values/specified/color.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/style/values/specified/color.rs b/components/style/values/specified/color.rs index 3be551d27a4..59184775c84 100644 --- a/components/style/values/specified/color.rs +++ b/components/style/values/specified/color.rs @@ -245,6 +245,12 @@ pub enum SystemColor { MozGtkInfoBarText, + /// Color of tree column headers + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] + MozColheadertext, + #[parse(condition = "ParserContext::in_ua_or_chrome_sheet")] + MozColheaderhovertext, + #[css(skip)] End, // Just for array-indexing purposes. } From 7b5953da9504e87a06a7d701f5e00c98c477d2e3 Mon Sep 17 00:00:00 2001 From: neil Date: Wed, 10 Jun 2020 13:16:34 +0000 Subject: [PATCH 08/17] style: Remove the layout.css.scrollbar-width.enabled and layout.css.scrollbar-color.enabled prefs. Differential Revision: https://phabricator.services.mozilla.com/D78400 --- components/style/properties/longhands/inherited_ui.mako.rs | 6 ------ components/style/properties/longhands/ui.mako.rs | 2 -- 2 files changed, 8 deletions(-) diff --git a/components/style/properties/longhands/inherited_ui.mako.rs b/components/style/properties/longhands/inherited_ui.mako.rs index 25b53190964..bbe34209647 100644 --- a/components/style/properties/longhands/inherited_ui.mako.rs +++ b/components/style/properties/longhands/inherited_ui.mako.rs @@ -77,13 +77,7 @@ ${helpers.predefined_type( "Default::default()", engines="gecko", spec="https://drafts.csswg.org/css-scrollbars-1/#scrollbar-color", - gecko_pref="layout.css.scrollbar-color.enabled", - # Surprisingly, yes the computed value of scrollbar-color has no effect on - # Gecko scrollbar elements, since the value only matters on the scrollable - # element itself. - has_effect_on_gecko_scrollbars=False, animation_value_type="ScrollbarColor", boxed=True, ignored_when_colors_disabled=True, - enabled_in="chrome", )} diff --git a/components/style/properties/longhands/ui.mako.rs b/components/style/properties/longhands/ui.mako.rs index 8aaee392662..e205c82da99 100644 --- a/components/style/properties/longhands/ui.mako.rs +++ b/components/style/properties/longhands/ui.mako.rs @@ -27,8 +27,6 @@ ${helpers.single_keyword( engines="gecko", gecko_enum_prefix="StyleScrollbarWidth", animation_value_type="discrete", - gecko_pref="layout.css.scrollbar-width.enabled", - enabled_in="chrome", spec="https://drafts.csswg.org/css-scrollbars-1/#scrollbar-width" )} From 33b548ae644727f46fca8c875e4f1a845d3973c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 11 Jun 2020 11:27:58 +0000 Subject: [PATCH 09/17] style: Use an enum class for LookAndFeel::FontID. Differential Revision: https://phabricator.services.mozilla.com/D76696 --- components/style/properties/longhands/font.mako.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/style/properties/longhands/font.mako.rs b/components/style/properties/longhands/font.mako.rs index 17836902740..86575720eba 100644 --- a/components/style/properties/longhands/font.mako.rs +++ b/components/style/properties/longhands/font.mako.rs @@ -369,7 +369,7 @@ ${helpers.predefined_type( let id = match *self { % for font in system_fonts: SystemFont::${to_camel_case(font)} => { - LookAndFeel_FontID::eFont_${to_camel_case(font.replace("-moz-", ""))} + LookAndFeel_FontID::${to_camel_case(font.replace("-moz-", ""))} } % endfor }; From 1f797ca24dcfb153477e6306360f292fab7eaee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Sun, 14 Jun 2020 23:26:04 +0000 Subject: [PATCH 10/17] style: Remove prefers-color-scheme: no-preference. It was removed from the spec. Differential Revision: https://phabricator.services.mozilla.com/D78834 --- components/style/gecko/media_features.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/style/gecko/media_features.rs b/components/style/gecko/media_features.rs index 4d60dc2ff26..a02ddcfd688 100644 --- a/components/style/gecko/media_features.rs +++ b/components/style/gecko/media_features.rs @@ -278,6 +278,10 @@ enum PrefersReducedMotion { Reduce, } +fn color_scheme_no_preference_enabled(_: &crate::parser::ParserContext) -> bool { + static_prefs::pref!("layout.css.prefers-color-scheme-no-preference.enabled") +} + /// Values for the prefers-color-scheme media feature. #[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)] #[repr(u8)] @@ -285,6 +289,7 @@ enum PrefersReducedMotion { pub enum PrefersColorScheme { Light, Dark, + #[parse(condition = "color_scheme_no_preference_enabled")] NoPreference, } From 56283a3226ac1b261181c5ceca82eaf3adf8fa16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 18 Jun 2020 17:35:17 +0200 Subject: [PATCH 11/17] style: Fix FontFamilyList definition. --- components/style/values/computed/font.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index d0b14b7e3fa..336408fb87a 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -477,10 +477,20 @@ impl From<&SingleFontFamily> for FontKitFamilyName { } } +#[cfg(feature = "servo")] #[derive( - Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem, + Clone, + Debug, + Deserialize, + Eq, + Hash, + MallocSizeOf, + PartialEq, + Serialize, + ToComputedValue, + ToResolvedValue, + ToShmem, )] -#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))] /// A list of SingleFontFamily pub struct FontFamilyList(Box<[SingleFontFamily]>); From 7a696cbffe781f0d8be339e4f9bfe63ee7da772c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 18 Jun 2020 17:37:12 +0200 Subject: [PATCH 12/17] style: build / rebase fixes. --- components/style/shared_lock.rs | 2 ++ components/style/values/specified/font.rs | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/components/style/shared_lock.rs b/components/style/shared_lock.rs index d151062199f..5bfa7d19737 100644 --- a/components/style/shared_lock.rs +++ b/components/style/shared_lock.rs @@ -258,6 +258,8 @@ impl Locked { #[cfg(feature = "gecko")] impl ToShmem for Locked { fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> to_shmem::Result { + use std::mem::ManuallyDrop; + let guard = self.shared_lock.read(); Ok(ManuallyDrop::new(Locked { shared_lock: SharedRwLock::read_only(), diff --git a/components/style/values/specified/font.rs b/components/style/values/specified/font.rs index 8ab48bfaf21..6fee8c2e770 100644 --- a/components/style/values/specified/font.rs +++ b/components/style/values/specified/font.rs @@ -498,10 +498,12 @@ impl ToComputedValue for FontStretch { ToCss, ToResolvedValue, ToShmem, + Serialize, + Deserialize, )] -#[cfg_attr(feature = "servo", derive(Serialize, Deserialize))] #[allow(missing_docs)] -pub enum KeywordSize { +#[repr(u8)] +pub enum FontSizeKeyword { #[css(keyword = "xx-small")] XXSmall, XSmall, @@ -794,6 +796,7 @@ impl FontSizeKeyword { FontSizeKeyword::XLarge => medium * 3.0 / 2.0, FontSizeKeyword::XXLarge => medium * 2.0, FontSizeKeyword::XXXLarge => medium * 3.0, + FontSizeKeyword::None => unreachable!(), }) } From e5484250db28c8ff5bfd5b71d5bac24be49e67f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 18 Jun 2020 19:23:59 +0200 Subject: [PATCH 13/17] style: Remove the dependency on font-kit from style. No good reason to have this IMO, and helps remove some #[cfg] blocks. --- Cargo.lock | 2 +- components/canvas/Cargo.toml | 1 + components/canvas/canvas_data.rs | 39 +++++++++++++++--- components/style/Cargo.toml | 1 - components/style/lib.rs | 2 - components/style/values/computed/font.rs | 51 ------------------------ 6 files changed, 35 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a0ff6a51af2..ea421cb5697 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -519,6 +519,7 @@ dependencies = [ "servo_config", "sparkle", "style", + "style_traits", "surfman", "surfman-chains", "surfman-chains-api", @@ -5466,7 +5467,6 @@ dependencies = [ "encoding_rs", "euclid", "fallible", - "font-kit", "fxhash", "hashglobe", "html5ever", diff --git a/components/canvas/Cargo.toml b/components/canvas/Cargo.toml index f0374c3df90..782e9fba4f0 100644 --- a/components/canvas/Cargo.toml +++ b/components/canvas/Cargo.toml @@ -37,6 +37,7 @@ servo_arc = { path = "../servo_arc" } servo_config = { path = "../config" } sparkle = "0.1.25" style = { path = "../style" } +style_traits = { path = "../style_traits" } # NOTE: the sm-angle feature only enables ANGLE on Windows, not other platforms! surfman = { version = "0.2", features = ["sm-angle", "sm-angle-default"] } surfman-chains = "0.3" diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 402c2690257..027c6a3155c 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -11,7 +11,7 @@ use euclid::{point2, vec2}; use font_kit::family_name::FamilyName; use font_kit::font::Font; use font_kit::metrics::Metrics; -use font_kit::properties::Properties; +use font_kit::properties::{Properties, Weight, Stretch, Style}; use font_kit::source::SystemSource; use gfx::font::FontHandleMethods; use gfx::font_cache_thread::FontCacheThread; @@ -25,6 +25,8 @@ use std::marker::PhantomData; use std::mem; use std::sync::{Arc, Mutex}; use style::properties::style_structs::Font as FontStyleStruct; +use style::values::computed::font; +use style_traits::values::ToCss; use webrender_api::units::RectExt as RectExt_; /// The canvas data stores a state machine for the current status of @@ -1372,6 +1374,24 @@ impl RectExt for Rect { } } +fn to_font_kit_family(font_family: &font::SingleFontFamily) -> FamilyName { + match font_family { + font::SingleFontFamily::FamilyName(family_name) => { + FamilyName::Title(family_name.to_css_string()) + }, + font::SingleFontFamily::Generic(generic) => match generic { + font::GenericFontFamily::Serif => FamilyName::Serif, + font::GenericFontFamily::SansSerif => FamilyName::SansSerif, + font::GenericFontFamily::Monospace => FamilyName::Monospace, + font::GenericFontFamily::Fantasy => FamilyName::Fantasy, + font::GenericFontFamily::Cursive => FamilyName::Cursive, + font::GenericFontFamily::None => { + unreachable!("Shouldn't appear in computed values") + }, + }, + } +} + fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Font { let mut properties = Properties::new(); let style = match font_style { @@ -1382,12 +1402,19 @@ fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Font { .font_family .families .iter() - .map(|family_name| family_name.into()) - .collect::>(); + .map(to_font_kit_family) + .collect::>(); let properties = properties - .style(style.font_style.into()) - .weight(style.font_weight.into()) - .stretch(style.font_stretch.into()); + .style(match style.font_style { + font::FontStyle::Normal => Style::Normal, + font::FontStyle::Italic => Style::Italic, + font::FontStyle::Oblique(..) => { + // TODO: support oblique angle. + Style::Oblique + } + }) + .weight(Weight(style.font_weight.0)) + .stretch(Stretch(style.font_stretch.value())); let font_handle = match SystemSource::new().select_best_match(&family_names, &properties) { Ok(handle) => handle, Err(e) => { diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml index 4baf6d381ef..91e26f7c06e 100644 --- a/components/style/Cargo.toml +++ b/components/style/Cargo.toml @@ -40,7 +40,6 @@ derive_more = "0.99" encoding_rs = { version = "0.8", optional = true } euclid = "0.20" fallible = { path = "../fallible" } -font-kit = "0.7" fxhash = "0.2" hashglobe = { path = "../hashglobe" } html5ever = { version = "0.25", optional = true } diff --git a/components/style/lib.rs b/components/style/lib.rs index 7ff69ed3c7b..52b77a7507e 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -40,8 +40,6 @@ extern crate debug_unreachable; extern crate derive_more; extern crate euclid; extern crate fallible; -#[cfg(feature = "servo")] -extern crate font_kit; extern crate fxhash; #[cfg(feature = "gecko")] #[macro_use] diff --git a/components/style/values/computed/font.rs b/components/style/values/computed/font.rs index 336408fb87a..b8d2cb4c680 100644 --- a/components/style/values/computed/font.rs +++ b/components/style/values/computed/font.rs @@ -22,12 +22,6 @@ use crate::values::specified::length::{FontBaseSize, NoCalcLength}; use crate::values::CSSFloat; use crate::Atom; use cssparser::{serialize_identifier, CssStringWriter, Parser}; -#[cfg(feature = "servo")] -use font_kit::family_name::FamilyName as FontKitFamilyName; -#[cfg(feature = "servo")] -use font_kit::properties::{ - Stretch as FontKitFontStretch, Style as FontKitFontStyle, Weight as FontKitFontWeight, -}; #[cfg(feature = "gecko")] use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; use std::fmt::{self, Write}; @@ -75,13 +69,6 @@ impl ToAnimatedValue for FontWeight { } } -#[cfg(feature = "servo")] -impl From for FontKitFontWeight { - fn from(font_weight: FontWeight) -> Self { - FontKitFontWeight(font_weight.0) - } -} - #[derive( Animate, Clone, @@ -457,26 +444,6 @@ impl SingleFontFamily { } } -#[cfg(feature = "servo")] -impl From<&SingleFontFamily> for FontKitFamilyName { - fn from(font_family: &SingleFontFamily) -> Self { - match font_family { - SingleFontFamily::FamilyName(family_name) => { - FontKitFamilyName::Title(family_name.to_css_string()) - }, - SingleFontFamily::Generic(GenericFontFamily::Serif) => FontKitFamilyName::Serif, - SingleFontFamily::Generic(GenericFontFamily::SansSerif) => FontKitFamilyName::SansSerif, - SingleFontFamily::Generic(GenericFontFamily::Monospace) => FontKitFamilyName::Monospace, - SingleFontFamily::Generic(GenericFontFamily::Fantasy) => FontKitFamilyName::Fantasy, - SingleFontFamily::Generic(GenericFontFamily::Cursive) => FontKitFamilyName::Cursive, - SingleFontFamily::Generic(family_name) => { - warn!("unsupported font family name: {:?}", family_name); - FontKitFamilyName::SansSerif - }, - } - } -} - #[cfg(feature = "servo")] #[derive( Clone, @@ -975,17 +942,6 @@ impl ToCss for FontStyle { } } -#[cfg(feature = "servo")] -impl From for FontKitFontStyle { - fn from(font_style: FontStyle) -> Self { - match font_style { - FontStyle::Normal => FontKitFontStyle::Normal, - FontStyle::Italic => FontKitFontStyle::Italic, - FontStyle::Oblique(_) => FontKitFontStyle::Oblique, - } - } -} - /// A value for the font-stretch property per: /// /// https://drafts.csswg.org/css-fonts-4/#propdef-font-stretch @@ -1008,13 +964,6 @@ impl FontStretch { } } -#[cfg(feature = "servo")] -impl From for FontKitFontStretch { - fn from(stretch: FontStretch) -> Self { - FontKitFontStretch(stretch.value()) - } -} - impl ToAnimatedValue for FontStretch { type AnimatedValue = Percentage; From 059a50bba0651480f2019bcd47e2de8042e95bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 18 Jun 2020 19:38:52 +0200 Subject: [PATCH 14/17] style: Remove some unused extern crate declarations now that style is in rust 2018. This avoids some warnings. --- components/style/build.rs | 9 ------ components/style/encoding_support.rs | 2 -- components/style/lib.rs | 43 ++-------------------------- 3 files changed, 2 insertions(+), 52 deletions(-) diff --git a/components/style/build.rs b/components/style/build.rs index 1d5211d690b..2247e876181 100644 --- a/components/style/build.rs +++ b/components/style/build.rs @@ -4,15 +4,6 @@ #[macro_use] extern crate lazy_static; -#[cfg(feature = "gecko")] -extern crate bindgen; -#[cfg(feature = "gecko")] -extern crate log; -#[cfg(feature = "gecko")] -extern crate regex; -#[cfg(feature = "gecko")] -extern crate toml; -extern crate walkdir; use std::env; use std::path::Path; diff --git a/components/style/encoding_support.rs b/components/style/encoding_support.rs index 1ba92953bb9..c144ad0b3bc 100644 --- a/components/style/encoding_support.rs +++ b/components/style/encoding_support.rs @@ -4,8 +4,6 @@ //! Parsing stylesheets from bytes (not `&str`). -extern crate encoding_rs; - use crate::context::QuirksMode; use crate::error_reporting::ParseErrorReporter; use crate::media_queries::MediaList; diff --git a/components/style/lib.rs b/components/style/lib.rs index 52b77a7507e..8b8af1073ae 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -25,32 +25,20 @@ #![deny(missing_docs)] -extern crate app_units; -extern crate arrayvec; -extern crate atomic_refcell; #[macro_use] extern crate bitflags; -#[allow(unused_extern_crates)] -extern crate byteorder; #[macro_use] extern crate cssparser; #[macro_use] extern crate debug_unreachable; #[macro_use] extern crate derive_more; -extern crate euclid; -extern crate fallible; -extern crate fxhash; #[cfg(feature = "gecko")] #[macro_use] pub mod gecko_string_cache; -extern crate hashglobe; #[cfg(feature = "servo")] #[macro_use] extern crate html5ever; -extern crate indexmap; -extern crate itertools; -extern crate itoa; #[macro_use] extern crate lazy_static; #[macro_use] @@ -60,48 +48,21 @@ extern crate malloc_size_of; #[macro_use] extern crate malloc_size_of_derive; #[cfg(feature = "gecko")] -pub extern crate nsstring; +pub use nsstring; #[cfg(feature = "gecko")] extern crate num_cpus; #[macro_use] extern crate num_derive; -extern crate num_integer; -extern crate num_traits; -extern crate owning_ref; -extern crate parking_lot; -extern crate precomputed_hash; -extern crate rayon; -extern crate selectors; #[macro_use] extern crate serde; -pub extern crate servo_arc; +pub use servo_arc; #[cfg(feature = "servo")] #[macro_use] extern crate servo_atoms; -#[cfg(feature = "servo")] -extern crate servo_config; -#[cfg(feature = "servo")] -extern crate servo_url; -extern crate smallbitvec; -extern crate smallvec; -#[cfg(feature = "gecko")] -extern crate static_prefs; -#[cfg(feature = "servo")] -extern crate string_cache; #[macro_use] extern crate style_derive; -extern crate style_traits; -#[cfg(feature = "gecko")] -extern crate thin_slice; -extern crate time; -extern crate to_shmem; #[macro_use] extern crate to_shmem_derive; -extern crate uluru; -extern crate unicode_bidi; -#[allow(unused_extern_crates)] -extern crate unicode_segmentation; -extern crate void; #[macro_use] mod macros; From 97f29c893f19eb0edb890ba2a57e6bdb164d258b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 18 Jun 2020 20:03:04 +0200 Subject: [PATCH 15/17] style: Fix gecko build. --- components/style/animation.rs | 7 +++--- components/style/dom.rs | 12 ---------- components/style/gecko/wrapper.rs | 24 ++++++++++--------- components/style/matching.rs | 5 ++-- .../style/properties/declaration_block.rs | 2 +- components/style/style_resolver.rs | 2 +- components/style/values/specified/box.rs | 9 +++---- 7 files changed, 27 insertions(+), 34 deletions(-) diff --git a/components/style/animation.rs b/components/style/animation.rs index 78b15d22cfb..197ba5be0cf 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -889,7 +889,8 @@ impl ElementAnimationSet { } } - pub(crate) fn apply_active_animations( + /// Apply all active animations. + pub fn apply_active_animations( &self, context: &SharedStyleContext, style: &mut Arc, @@ -1237,7 +1238,7 @@ impl DocumentAnimationSet { /// Get all the animation declarations for the given key, returning an empty /// `AnimationDeclarations` if there are no animations. - pub(crate) fn get_all_declarations( + pub fn get_all_declarations( &self, key: &AnimationSetKey, time: f64, @@ -1264,7 +1265,7 @@ impl DocumentAnimationSet { } /// Cancel all animations for set at the given key. - pub(crate) fn cancel_all_animations_for_key(&self, key: &AnimationSetKey) { + pub fn cancel_all_animations_for_key(&self, key: &AnimationSetKey) { if let Some(set) = self.sets.write().get_mut(key) { set.cancel_all_animations(); } diff --git a/components/style/dom.rs b/components/style/dom.rs index a61739b920e..60e1be054d6 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -884,18 +884,6 @@ pub trait TElement: doc_rules_apply } - /// Does a rough (and cheap) check for whether or not transitions might need to be updated that - /// will quickly return false for the common case of no transitions specified or running. If - /// this returns false, we definitely don't need to update transitions but if it returns true - /// we can perform the more thoroughgoing check, needs_transitions_update, to further - /// reduce the possibility of false positives. - #[cfg(feature = "gecko")] - fn might_need_transitions_update( - &self, - old_values: Option<&ComputedValues>, - new_values: &ComputedValues, - ) -> bool; - /// Returns true if one of the transitions needs to be updated on this element. We check all /// the transition properties to make sure that updating transitions is necessary. /// This method should only be called if might_needs_transitions_update returns true when diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index e301bdd1107..9d63be36cd4 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -567,6 +567,12 @@ impl<'le> GeckoElement<'le> { unsafe { self.0.mServoData.get().as_ref() } } + /// Returns whether any animation applies to this element. + #[inline] + pub fn has_any_animation(&self) -> bool { + self.may_have_animations() && unsafe { Gecko_ElementHasAnimations(self.0) } + } + #[inline(always)] fn attrs(&self) -> &[structs::AttrArray_InternalAttr] { unsafe { @@ -1235,11 +1241,11 @@ impl<'le> TElement for GeckoElement<'le> { } } - fn animation_rule(&self) -> Option>> { + fn animation_rule(&self, _: &SharedStyleContext) -> Option>> { get_animation_rule(self, CascadeLevel::Animations) } - fn transition_rule(&self) -> Option>> { + fn transition_rule(&self, _: &SharedStyleContext) -> Option>> { get_animation_rule(self, CascadeLevel::Transitions) } @@ -1516,8 +1522,9 @@ impl<'le> TElement for GeckoElement<'le> { } } - fn has_animations(&self) -> bool { - self.may_have_animations() && unsafe { Gecko_ElementHasAnimations(self.0) } + #[inline] + fn has_animations(&self, _: &SharedStyleContext) -> bool { + self.has_any_animation() } fn has_css_animations(&self, _: &SharedStyleContext, _: Option) -> bool { @@ -1529,7 +1536,8 @@ impl<'le> TElement for GeckoElement<'le> { } // Detect if there are any changes that require us to update transitions. - // This is used as a more thoroughgoing check than the, cheaper + // + // This is used as a more thoroughgoing check than the cheaper // might_need_transitions_update check. // // The following logic shadows the logic used on the Gecko side @@ -1544,12 +1552,6 @@ impl<'le> TElement for GeckoElement<'le> { ) -> bool { use crate::properties::LonghandIdSet; - debug_assert!( - self.might_need_transitions_update(Some(before_change_style), after_change_style), - "We should only call needs_transitions_update if \ - might_need_transitions_update returns true" - ); - let after_change_box_style = after_change_style.get_box(); let existing_transitions = self.css_transitions_info(); let mut transitions_to_keep = LonghandIdSet::new(); diff --git a/components/style/matching.rs b/components/style/matching.rs index 31ba54a37e0..8e4398bc8c2 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -391,6 +391,7 @@ trait PrivateMatchMethods: TElement { use crate::context::UpdateAnimationsTasks; let new_values = new_styles.primary_style_mut(); + let old_values = &old_styles.primary; if context.shared.traversal_flags.for_animation_only() { self.handle_display_change_for_smil_if_needed( context, @@ -420,7 +421,7 @@ trait PrivateMatchMethods: TElement { new_values, /* pseudo_element = */ None, ) { - let after_change_style = if self.has_css_transitions(context.shared) { + let after_change_style = if self.has_css_transitions(context.shared, /* pseudo_element = */ None) { self.after_change_style(context, new_values) } else { None @@ -453,7 +454,7 @@ trait PrivateMatchMethods: TElement { None }; - if self.has_animations() { + if self.has_animations(&context.shared) { tasks.insert(UpdateAnimationsTasks::EFFECT_PROPERTIES); if important_rules_changed { tasks.insert(UpdateAnimationsTasks::CASCADE_RESULTS); diff --git a/components/style/properties/declaration_block.rs b/components/style/properties/declaration_block.rs index 2bb7a8c7442..fe52e6059c7 100644 --- a/components/style/properties/declaration_block.rs +++ b/components/style/properties/declaration_block.rs @@ -39,7 +39,7 @@ pub struct AnimationDeclarations { impl AnimationDeclarations { /// Whether or not this `AnimationDeclarations` is empty. - pub(crate) fn is_empty(&self) -> bool { + pub fn is_empty(&self) -> bool { self.animations.is_none() && self.transitions.is_none() } } diff --git a/components/style/style_resolver.rs b/components/style/style_resolver.rs index c1f20ee0c27..8caf3cec4c3 100644 --- a/components/style/style_resolver.rs +++ b/components/style/style_resolver.rs @@ -307,7 +307,7 @@ where } /// Cascade a set of rules for pseudo element, using the default parent for inheritance. - pub(crate) fn cascade_style_and_visited_for_pseudo_with_default_parents( + pub fn cascade_style_and_visited_for_pseudo_with_default_parents( &mut self, inputs: CascadeInputs, pseudo: &PseudoElement, diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 676262500f0..6fc86b48678 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -35,14 +35,15 @@ fn moz_box_display_values_enabled(context: &ParserContext) -> bool { } fn flexbox_enabled() -> bool { - if cfg!(feature = "servo-layout-2020") { - servo_config::prefs::pref_map() + #[cfg(feature = "servo-layout-2020")] + { + return servo_config::prefs::pref_map() .get("layout.flexbox.enabled") .as_bool() .unwrap_or(false) - } else { - true } + + true } /// Defines an element’s display type, which consists of From bb8c3ee8ba0445ff22709ffb5bae283fafe10fb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 18 Jun 2020 20:27:58 +0200 Subject: [PATCH 16/17] style: fix formatting. --- components/canvas/canvas_data.rs | 8 +++----- components/style/gecko/wrapper.rs | 10 ++++++++-- components/style/matching.rs | 11 ++++++----- components/style/values/specified/box.rs | 2 +- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/components/canvas/canvas_data.rs b/components/canvas/canvas_data.rs index 027c6a3155c..706648e8bf3 100644 --- a/components/canvas/canvas_data.rs +++ b/components/canvas/canvas_data.rs @@ -11,7 +11,7 @@ use euclid::{point2, vec2}; use font_kit::family_name::FamilyName; use font_kit::font::Font; use font_kit::metrics::Metrics; -use font_kit::properties::{Properties, Weight, Stretch, Style}; +use font_kit::properties::{Properties, Stretch, Style, Weight}; use font_kit::source::SystemSource; use gfx::font::FontHandleMethods; use gfx::font_cache_thread::FontCacheThread; @@ -1385,9 +1385,7 @@ fn to_font_kit_family(font_family: &font::SingleFontFamily) -> FamilyName { font::GenericFontFamily::Monospace => FamilyName::Monospace, font::GenericFontFamily::Fantasy => FamilyName::Fantasy, font::GenericFontFamily::Cursive => FamilyName::Cursive, - font::GenericFontFamily::None => { - unreachable!("Shouldn't appear in computed values") - }, + font::GenericFontFamily::None => unreachable!("Shouldn't appear in computed values"), }, } } @@ -1411,7 +1409,7 @@ fn load_system_font_from_style(font_style: Option<&FontStyleStruct>) -> Font { font::FontStyle::Oblique(..) => { // TODO: support oblique angle. Style::Oblique - } + }, }) .weight(Weight(style.font_weight.0)) .stretch(Stretch(style.font_stretch.value())); diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 9d63be36cd4..8184ccaa3e4 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -1241,11 +1241,17 @@ impl<'le> TElement for GeckoElement<'le> { } } - fn animation_rule(&self, _: &SharedStyleContext) -> Option>> { + fn animation_rule( + &self, + _: &SharedStyleContext, + ) -> Option>> { get_animation_rule(self, CascadeLevel::Animations) } - fn transition_rule(&self, _: &SharedStyleContext) -> Option>> { + fn transition_rule( + &self, + _: &SharedStyleContext, + ) -> Option>> { get_animation_rule(self, CascadeLevel::Transitions) } diff --git a/components/style/matching.rs b/components/style/matching.rs index 8e4398bc8c2..c74d4feda3c 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -421,11 +421,12 @@ trait PrivateMatchMethods: TElement { new_values, /* pseudo_element = */ None, ) { - let after_change_style = if self.has_css_transitions(context.shared, /* pseudo_element = */ None) { - self.after_change_style(context, new_values) - } else { - None - }; + let after_change_style = + if self.has_css_transitions(context.shared, /* pseudo_element = */ None) { + self.after_change_style(context, new_values) + } else { + None + }; // In order to avoid creating a SequentialTask for transitions which // may not be updated, we check it per property to make sure Gecko diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 6fc86b48678..aeaa1930675 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -40,7 +40,7 @@ fn flexbox_enabled() -> bool { return servo_config::prefs::pref_map() .get("layout.flexbox.enabled") .as_bool() - .unwrap_or(false) + .unwrap_or(false); } true From a7d740331d392b1e76c9f253943d7cd0c6a10f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Thu, 18 Jun 2020 23:50:39 +0200 Subject: [PATCH 17/17] style: Fix a warning in layout-2020 --- components/style/values/specified/box.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index aeaa1930675..aeebc999261 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -34,18 +34,19 @@ fn moz_box_display_values_enabled(context: &ParserContext) -> bool { static_prefs::pref!("layout.css.xul-box-display-values.content.enabled") } +#[cfg(not(feature = "servo-layout-2020"))] fn flexbox_enabled() -> bool { - #[cfg(feature = "servo-layout-2020")] - { - return servo_config::prefs::pref_map() - .get("layout.flexbox.enabled") - .as_bool() - .unwrap_or(false); - } - true } +#[cfg(feature = "servo-layout-2020")] +fn flexbox_enabled() -> bool { + servo_config::prefs::pref_map() + .get("layout.flexbox.enabled") + .as_bool() + .unwrap_or(false) +} + /// Defines an element’s display type, which consists of /// the two basic qualities of how an element generates boxes ///