diff --git a/components/style/custom_properties.rs b/components/style/custom_properties.rs index b7ef6cf21d0..76a72276a44 100644 --- a/components/style/custom_properties.rs +++ b/components/style/custom_properties.rs @@ -12,7 +12,9 @@ use crate::properties::{CSSWideKeyword, CustomDeclaration, CustomDeclarationValu use crate::selector_map::{PrecomputedHashMap, PrecomputedHashSet, PrecomputedHasher}; use crate::stylesheets::{Origin, PerOrigin}; use crate::Atom; -use cssparser::{CowRcStr, Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType}; +use cssparser::{ + CowRcStr, Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType, +}; use indexmap::IndexMap; use selectors::parser::SelectorParseErrorKind; use servo_arc::Arc; @@ -525,10 +527,7 @@ pub struct CustomPropertiesBuilder<'a> { impl<'a> CustomPropertiesBuilder<'a> { /// Create a new builder, inheriting from a given custom properties map. - pub fn new( - inherited: Option<&'a Arc>, - device: &'a Device, - ) -> Self { + pub fn new(inherited: Option<&'a Arc>, device: &'a Device) -> Self { Self { seen: PrecomputedHashSet::default(), reverted: Default::default(), @@ -576,8 +575,7 @@ impl<'a> CustomPropertiesBuilder<'a> { // environment variable here, perform substitution here instead // of forcing a full traversal in `substitute_all` afterwards. let value = if !has_references && unparsed_value.references_environment { - let result = - substitute_references_in_value(unparsed_value, &map, &self.device); + let result = substitute_references_in_value(unparsed_value, &map, &self.device); match result { Ok(new_value) => Arc::new(new_value), Err(..) => { diff --git a/components/style/gecko/media_queries.rs b/components/style/gecko/media_queries.rs index ae4bad7a25a..25ce9f5b3a1 100644 --- a/components/style/gecko/media_queries.rs +++ b/components/style/gecko/media_queries.rs @@ -138,7 +138,8 @@ impl Device { /// Set the font size of the root element (for rem) pub fn set_root_font_size(&self, size: Au) { - self.root_font_size.store(size.0 as isize, Ordering::Relaxed) + self.root_font_size + .store(size.0 as isize, Ordering::Relaxed) } /// Sets the body text color for the "inherit color from body" quirk. diff --git a/components/style/lib.rs b/components/style/lib.rs index 506c309c300..6c4b1d5a2a9 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -119,7 +119,7 @@ pub mod attr; pub mod author_styles; pub mod bezier; pub mod bloom; -#[path="properties/computed_value_flags.rs"] +#[path = "properties/computed_value_flags.rs"] pub mod computed_value_flags; pub mod context; pub mod counter_style; diff --git a/components/style/matching.rs b/components/style/matching.rs index 42921f052c4..06e74810cfd 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -706,7 +706,10 @@ pub trait MatchMethods: TElement { let new_primary_style = data.styles.primary.as_ref().unwrap(); let mut cascade_requirement = ChildCascadeRequirement::CanSkipCascade; - if new_primary_style.flags.contains(ComputedValueFlags::IS_ROOT_ELEMENT_STYLE) { + if new_primary_style + .flags + .contains(ComputedValueFlags::IS_ROOT_ELEMENT_STYLE) + { let device = context.shared.stylist.device(); let new_font_size = new_primary_style.get_font().clone_font_size(); diff --git a/components/style/properties/computed_value_flags.rs b/components/style/properties/computed_value_flags.rs index 170c4151411..4363f3f36e9 100644 --- a/components/style/properties/computed_value_flags.rs +++ b/components/style/properties/computed_value_flags.rs @@ -75,9 +75,9 @@ impl ComputedValueFlags { #[inline] fn inherited_flags() -> Self { ComputedValueFlags::IS_RELEVANT_LINK_VISITED | - ComputedValueFlags::CAN_BE_FRAGMENTED | - ComputedValueFlags::IS_IN_PSEUDO_ELEMENT_SUBTREE | - ComputedValueFlags::HAS_TEXT_DECORATION_LINES + ComputedValueFlags::CAN_BE_FRAGMENTED | + ComputedValueFlags::IS_IN_PSEUDO_ELEMENT_SUBTREE | + ComputedValueFlags::HAS_TEXT_DECORATION_LINES } /// Flags that may be propagated to descendants. diff --git a/components/style/rule_tree/mod.rs b/components/style/rule_tree/mod.rs index 9def9108046..113fa9cb9bb 100644 --- a/components/style/rule_tree/mod.rs +++ b/components/style/rule_tree/mod.rs @@ -1767,12 +1767,19 @@ impl Drop for StrongRuleNode { crash_str.push(b'\n'); } children.each(|child| { - (*child.ptr()).source.as_ref().unwrap().dump_unchecked(&mut crash_str); + (*child.ptr()) + .source + .as_ref() + .unwrap() + .dump_unchecked(&mut crash_str); crash_str.push(b'\n'); }); } - panic!("Children left in the rule tree on drop: {}", String::from_utf8_lossy(&crash_str).trim()); + panic!( + "Children left in the rule tree on drop: {}", + String::from_utf8_lossy(&crash_str).trim() + ); } } diff --git a/components/style/servo/media_queries.rs b/components/style/servo/media_queries.rs index fa288a92729..8c0ac014437 100644 --- a/components/style/servo/media_queries.rs +++ b/components/style/servo/media_queries.rs @@ -16,7 +16,7 @@ use crate::values::KeyframesName; use app_units::Au; use cssparser::RGBA; use euclid::default::Size2D as UntypedSize2D; -use euclid::{Scale, Size2D, SideOffsets2D}; +use euclid::{Scale, SideOffsets2D, Size2D}; use std::sync::atomic::{AtomicBool, AtomicIsize, Ordering}; use style_traits::viewport::ViewportConstraints; use style_traits::{CSSPixel, DevicePixel}; diff --git a/components/style/sharing/mod.rs b/components/style/sharing/mod.rs index 2d36aeea7ff..7f85104cb7c 100644 --- a/components/style/sharing/mod.rs +++ b/components/style/sharing/mod.rs @@ -173,7 +173,7 @@ impl ValidationData { E: TElement, { if !element.has_part_attr() { - return &[] + return &[]; } self.part_list.get_or_insert_with(|| { let mut list = SmallVec::<[Atom; 5]>::new(); diff --git a/components/style/style_adjuster.rs b/components/style/style_adjuster.rs index b7c1decc390..a2c6e5a2928 100644 --- a/components/style/style_adjuster.rs +++ b/components/style/style_adjuster.rs @@ -204,7 +204,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { self.style.pseudo.map_or(false, |p| p.is_marker()) && self.style.get_parent_list().clone_list_style_position() == ListStylePosition::Outside && - !layout_parent_style.get_box().clone_display().is_inline_flow() + !layout_parent_style + .get_box() + .clone_display() + .is_inline_flow() ); if !blockify { @@ -241,7 +244,8 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { } if self.style.is_root_element { - self.style.add_flags(ComputedValueFlags::IS_ROOT_ELEMENT_STYLE); + self.style + .add_flags(ComputedValueFlags::IS_ROOT_ELEMENT_STYLE); } #[cfg(feature = "servo-layout-2013")] @@ -285,8 +289,10 @@ impl<'a, 'b: 'a> StyleAdjuster<'a, 'b> { let writing_mode = self.style.get_inherited_box().clone_writing_mode(); let text_combine_upright = self.style.get_inherited_text().clone_text_combine_upright(); - if matches!(writing_mode, WritingMode::VerticalRl | WritingMode::VerticalLr) && - text_combine_upright == TextCombineUpright::All + if matches!( + writing_mode, + WritingMode::VerticalRl | WritingMode::VerticalLr + ) && text_combine_upright == TextCombineUpright::All { self.style.add_flags(ComputedValueFlags::IS_TEXT_COMBINED); self.style diff --git a/components/style/values/animated/length.rs b/components/style/values/animated/length.rs index 09724362441..04690446e64 100644 --- a/components/style/values/animated/length.rs +++ b/components/style/values/animated/length.rs @@ -30,6 +30,10 @@ impl Animate for LengthPercentage { // Gets clamped as needed after the animation if needed, so no need to // specify any particular AllowedNumericType. - Ok(LengthPercentage::new_calc(length, percentage, AllowedNumericType::All)) + Ok(LengthPercentage::new_calc( + length, + percentage, + AllowedNumericType::All, + )) } } diff --git a/components/style/values/computed/align.rs b/components/style/values/computed/align.rs index c76c9018ac2..45d6cfac323 100644 --- a/components/style/values/computed/align.rs +++ b/components/style/values/computed/align.rs @@ -9,7 +9,9 @@ use crate::values::computed::{Context, ToComputedValue}; use crate::values::specified; -pub use super::specified::{AlignContent, AlignItems, ContentDistribution, JustifyContent, SelfAlignment}; +pub use super::specified::{ + AlignContent, AlignItems, ContentDistribution, JustifyContent, SelfAlignment, +}; pub use super::specified::{AlignSelf, JustifySelf}; /// The computed value for the `justify-items` property. diff --git a/components/style/values/computed/length.rs b/components/style/values/computed/length.rs index 0c59b640558..eedd05d1f15 100644 --- a/components/style/values/computed/length.rs +++ b/components/style/values/computed/length.rs @@ -21,9 +21,9 @@ use std::ops::{Add, AddAssign, Div, Mul, Neg, Sub}; use style_traits::{CSSPixel, CssWriter, ToCss}; pub use super::image::Image; +pub use super::length_percentage::{LengthPercentage, NonNegativeLengthPercentage}; pub use crate::values::specified::url::UrlOrNone; pub use crate::values::specified::{Angle, BorderStyle, Time}; -pub use super::length_percentage::{LengthPercentage, NonNegativeLengthPercentage}; impl ToComputedValue for specified::NoCalcLength { type ComputedValue = Length; @@ -57,7 +57,9 @@ impl ToComputedValue for specified::Length { fn to_computed_value(&self, context: &Context) -> Self::ComputedValue { match *self { specified::Length::NoCalc(l) => l.to_computed_value(context), - specified::Length::Calc(ref calc) => calc.to_computed_value(context).to_length().unwrap(), + specified::Length::Calc(ref calc) => { + calc.to_computed_value(context).to_length().unwrap() + }, } } diff --git a/components/style/values/computed/length_percentage.rs b/components/style/values/computed/length_percentage.rs index 7c1e831f7df..14b894e1da4 100644 --- a/components/style/values/computed/length_percentage.rs +++ b/components/style/values/computed/length_percentage.rs @@ -33,13 +33,13 @@ use crate::values::{specified, CSSFloat}; use crate::Zero; use app_units::Au; use malloc_size_of::{MallocSizeOf, MallocSizeOfOps}; -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use std::fmt::{self, Write}; use style_traits::values::specified::AllowedNumericType; use style_traits::{CssWriter, ToCss}; #[doc(hidden)] -#[derive(Copy, Clone)] +#[derive(Clone, Copy)] #[repr(C)] pub struct LengthVariant { tag: u32, @@ -47,7 +47,7 @@ pub struct LengthVariant { } #[doc(hidden)] -#[derive(Copy, Clone)] +#[derive(Clone, Copy)] #[repr(C)] pub struct PercentageVariant { tag: u32, @@ -57,7 +57,7 @@ pub struct PercentageVariant { // NOTE(emilio): cbindgen only understands the #[cfg] on the top level // definition. #[doc(hidden)] -#[derive(Copy, Clone)] +#[derive(Clone, Copy)] #[repr(C)] #[cfg(target_pointer_width = "32")] pub struct CalcVariant { @@ -66,7 +66,7 @@ pub struct CalcVariant { } #[doc(hidden)] -#[derive(Copy, Clone)] +#[derive(Clone, Copy)] #[repr(C)] #[cfg(target_pointer_width = "64")] pub struct CalcVariant { @@ -78,7 +78,7 @@ unsafe impl Send for CalcVariant {} unsafe impl Sync for CalcVariant {} #[doc(hidden)] -#[derive(Copy, Clone)] +#[derive(Clone, Copy)] #[repr(C)] pub struct TagVariant { tag: u32, @@ -123,7 +123,7 @@ impl LengthPercentageUnion { pub const TAG_MASK: u32 = 0b11; } -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] #[repr(u32)] enum Tag { Calc = LengthPercentageUnion::TAG_CALC, @@ -171,7 +171,7 @@ enum Unpacked<'a> { /// An unpacked `` that owns the `calc()` variant, for /// serialization purposes. -#[derive(Deserialize, Serialize, PartialEq)] +#[derive(Deserialize, PartialEq, Serialize)] enum Serializable { Calc(CalcLengthPercentage), Length(Length), @@ -192,7 +192,7 @@ impl LengthPercentage { length: LengthVariant { tag: LengthPercentageUnion::TAG_LENGTH, length, - } + }, }); debug_assert_eq!(length.tag(), Tag::Length); length @@ -205,7 +205,7 @@ impl LengthPercentage { percentage: PercentageVariant { tag: LengthPercentageUnion::TAG_PERCENTAGE, percentage, - } + }, }); debug_assert_eq!(percent.tag(), Tag::Percentage); percent @@ -223,7 +223,7 @@ impl LengthPercentage { None => return Self::new_length(Length::new(clamping_mode.clamp(length.px()))), }; if length.is_zero() { - return Self::new_percent(Percentage(clamping_mode.clamp(percentage.0))) + return Self::new_percent(Percentage(clamping_mode.clamp(percentage.0))); } Self::new_calc_unchecked(Box::new(CalcLengthPercentage { length, @@ -241,7 +241,7 @@ impl LengthPercentage { #[cfg(target_pointer_width = "32")] tag: LengthPercentageUnion::TAG_CALC, ptr, - } + }, }); debug_assert_eq!(calc.tag(), Tag::Calc); calc @@ -293,7 +293,11 @@ impl LengthPercentage { Unpacked::Length(l) => l.px() == 0.0, Unpacked::Percentage(p) => p.0 == 0.0, Unpacked::Calc(ref c) => { - debug_assert_ne!(c.length.px(), 0.0, "Should've been simplified to a percentage"); + debug_assert_ne!( + c.length.px(), + 0.0, + "Should've been simplified to a percentage" + ); false }, } @@ -374,7 +378,7 @@ impl LengthPercentage { Unpacked::Percentage(..) | Unpacked::Calc(..) => { debug_assert!(self.has_percentage()); return None; - } + }, } } @@ -387,7 +391,7 @@ impl LengthPercentage { Unpacked::Calc(ref c) => { debug_assert!(!c.length.is_zero()); None - } + }, } } @@ -400,7 +404,7 @@ impl LengthPercentage { Unpacked::Calc(ref c) => { debug_assert!(self.has_percentage()); Some(c.percentage) - } + }, } } @@ -419,7 +423,8 @@ impl LengthPercentage { /// Convert the computed value into used value. #[inline] pub fn maybe_to_used_value(&self, container_len: Option) -> Option { - self.maybe_percentage_relative_to(container_len).map(Au::from) + self.maybe_percentage_relative_to(container_len) + .map(Au::from) } /// If there are special rules for computing percentages in a value (e.g. @@ -470,7 +475,7 @@ impl Clone for LengthPercentage { match self.unpack() { Unpacked::Length(l) => Self::new_length(l), Unpacked::Percentage(p) => Self::new_percent(p), - Unpacked::Calc(c) => Self::new_calc_unchecked(Box::new(c.clone())) + Unpacked::Calc(c) => Self::new_calc_unchecked(Box::new(c.clone())), } } } @@ -483,12 +488,8 @@ impl ToComputedValue for specified::LengthPercentage { specified::LengthPercentage::Length(ref value) => { LengthPercentage::new_length(value.to_computed_value(context)) }, - specified::LengthPercentage::Percentage(value) => { - LengthPercentage::new_percent(value) - }, - specified::LengthPercentage::Calc(ref calc) => { - (**calc).to_computed_value(context) - }, + specified::LengthPercentage::Percentage(value) => LengthPercentage::new_percent(value), + specified::LengthPercentage::Calc(ref calc) => (**calc).to_computed_value(context), } } @@ -496,15 +497,15 @@ impl ToComputedValue for specified::LengthPercentage { match computed.unpack() { Unpacked::Length(ref l) => { specified::LengthPercentage::Length(ToComputedValue::from_computed_value(l)) - } - Unpacked::Percentage(p) => { - specified::LengthPercentage::Percentage(p) - } + }, + Unpacked::Percentage(p) => specified::LengthPercentage::Percentage(p), Unpacked::Calc(c) => { // We simplify before constructing the LengthPercentage if // needed, so this is always fine. - specified::LengthPercentage::Calc(Box::new(specified::CalcLengthPercentage::from_computed_value(c))) - } + specified::LengthPercentage::Calc(Box::new( + specified::CalcLengthPercentage::from_computed_value(c), + )) + }, } } } @@ -517,7 +518,8 @@ impl ComputeSquaredDistance for LengthPercentage { // ensures that the distance between length-only and percentage-only // lengths makes sense. let basis = Length::new(100.); - self.resolve(basis).compute_squared_distance(&other.resolve(basis)) + self.resolve(basis) + .compute_squared_distance(&other.resolve(basis)) } } @@ -555,14 +557,14 @@ impl<'de> Deserialize<'de> for LengthPercentage { where D: serde::Deserializer<'de>, { - Ok(Self::from_serializable(Serializable::deserialize(deserializer)?)) + Ok(Self::from_serializable(Serializable::deserialize( + deserializer, + )?)) } } /// The representation of a calc() function with mixed lengths and percentages. -#[derive( - Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue, -)] +#[derive(Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToAnimatedZero, ToResolvedValue)] #[repr(C)] pub struct CalcLengthPercentage { length: Length, @@ -596,7 +598,11 @@ impl CalcLengthPercentage { /// Returns the clamped non-negative values. #[inline] fn clamp_to_non_negative(&self) -> LengthPercentage { - LengthPercentage::new_calc(self.length, Some(self.percentage), AllowedNumericType::NonNegative) + LengthPercentage::new_calc( + self.length, + Some(self.percentage), + AllowedNumericType::NonNegative, + ) } } @@ -629,8 +635,8 @@ impl specified::CalcLengthPercentage { where F: Fn(Length) -> Length, { + use crate::values::specified::length::{FontRelativeLength, ViewportPercentageLength}; use std::f32; - use crate::values::specified::length::{ViewportPercentageLength, FontRelativeLength}; let mut length = 0.; @@ -764,4 +770,3 @@ impl NonNegativeLengthPercentage { Some(std::cmp::max(resolved, Au(0))) } } - diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index aaa2677777b..7cfd1e20abe 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -501,11 +501,9 @@ impl ToComputedValue for specified::AngleOrPercentage { #[inline] fn from_computed_value(computed: &AngleOrPercentage) -> Self { match *computed { - AngleOrPercentage::Percentage(percentage) => { - specified::AngleOrPercentage::Percentage(ToComputedValue::from_computed_value( - &percentage, - )) - }, + AngleOrPercentage::Percentage(percentage) => specified::AngleOrPercentage::Percentage( + ToComputedValue::from_computed_value(&percentage), + ), AngleOrPercentage::Angle(angle) => { specified::AngleOrPercentage::Angle(ToComputedValue::from_computed_value(&angle)) }, diff --git a/components/style/values/generics/counters.rs b/components/style/values/generics/counters.rs index 88c83f87357..05e34703911 100644 --- a/components/style/values/generics/counters.rs +++ b/components/style/values/generics/counters.rs @@ -145,15 +145,7 @@ fn is_decimal(counter_type: &CounterStyleType) -> bool { /// /// https://drafts.csswg.org/css-content/#propdef-content #[derive( - Clone, - Debug, - Eq, - MallocSizeOf, - PartialEq, - SpecifiedValueInfo, - ToComputedValue, - ToCss, - ToShmem, + Clone, Debug, Eq, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToComputedValue, ToCss, ToShmem, )] #[repr(u8)] pub enum GenericContent { diff --git a/components/style/values/resolved/counters.rs b/components/style/values/resolved/counters.rs index daf70359061..bf6490f7401 100644 --- a/components/style/values/resolved/counters.rs +++ b/components/style/values/resolved/counters.rs @@ -23,8 +23,10 @@ impl ToResolvedValue for computed::Content { #[inline] fn to_resolved_value(self, context: &Context) -> Self { - let is_before_or_after = - context.style.pseudo().map_or(false, |p| p.is_before_or_after()); + let is_before_or_after = context + .style + .pseudo() + .map_or(false, |p| p.is_before_or_after()); match self { Self::Normal if is_before_or_after => Self::None, @@ -43,4 +45,3 @@ impl ToResolvedValue for computed::Content { resolved } } - diff --git a/components/style/values/specified/angle.rs b/components/style/values/specified/angle.rs index b42d5d5038f..fa60f66507d 100644 --- a/components/style/values/specified/angle.rs +++ b/components/style/values/specified/angle.rs @@ -228,9 +228,7 @@ impl Angle { let function = CalcNode::math_function(name, location)?; CalcNode::parse_angle(context, input, function) }, - Token::Number { value, .. } if value == 0. && allow_unitless_zero => { - Ok(Angle::zero()) - }, + Token::Number { value, .. } if value == 0. && allow_unitless_zero => Ok(Angle::zero()), ref t => { let t = t.clone(); Err(input.new_unexpected_token_error(t)) diff --git a/components/style/values/specified/box.rs b/components/style/values/specified/box.rs index 11fbe6afb7b..fa5d5a2d43a 100644 --- a/components/style/values/specified/box.rs +++ b/components/style/values/specified/box.rs @@ -267,8 +267,7 @@ impl Display { /// Whether this is `display: inline` (or `inline list-item`). #[inline] pub fn is_inline_flow(&self) -> bool { - self.outside() == DisplayOutside::Inline && - self.inside() == DisplayInside::Flow + self.outside() == DisplayOutside::Inline && self.inside() == DisplayInside::Flow } /// Returns whether this `display` value is some kind of list-item. diff --git a/components/style/values/specified/calc.rs b/components/style/values/specified/calc.rs index d008792eee5..9736491adce 100644 --- a/components/style/values/specified/calc.rs +++ b/components/style/values/specified/calc.rs @@ -20,7 +20,7 @@ use style_traits::values::specified::AllowedNumericType; use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKind, ToCss}; /// The name of the mathematical function that we're parsing. -#[derive(Debug, Copy, Clone)] +#[derive(Clone, Copy, Debug)] pub enum MathFunction { /// `calc()`: https://drafts.csswg.org/css-values-4/#funcdef-calc Calc, @@ -36,7 +36,7 @@ pub enum MathFunction { /// sum. /// /// See https://drafts.csswg.org/css-values-4/#sort-a-calculations-children -#[derive(Debug, Copy, Clone, Eq, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] enum SortKey { Number, Percentage, @@ -55,7 +55,7 @@ enum SortKey { } /// Whether we're a `min` or `max` function. -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq)] pub enum MinMaxOp { /// `min()` Min, @@ -216,7 +216,11 @@ macro_rules! impl_generic_to_type { } $from_float(sum) }, - Self::Clamp { ref min, ref center, ref max } => { + Self::Clamp { + ref min, + ref center, + ref max, + } => { let min = min.$to_self()?; let center = center.$to_self()?; let max = max.$to_self()?; @@ -265,7 +269,7 @@ macro_rules! impl_generic_to_type { Self::Percentage(..) | Self::Number(..) => return Err(()), }) - }} + }}; } impl PartialOrd for CalcNode { @@ -327,7 +331,11 @@ impl CalcNode { } }, // Multiplication is distributive across these. - Self::Clamp { ref mut min, ref mut center, ref mut max } => { + Self::Clamp { + ref mut min, + ref mut center, + ref mut max, + } => { min.mul_by(scalar); center.mul_by(scalar); max.mul_by(scalar); @@ -345,27 +353,21 @@ impl CalcNode { Self::Percentage(..) => SortKey::Percentage, Self::Time(..) => SortKey::Sec, Self::Angle(..) => SortKey::Deg, - Self::Length(ref l) => { - match *l { - NoCalcLength::Absolute(..) => SortKey::Px, - NoCalcLength::FontRelative(ref relative) => { - match *relative { - FontRelativeLength::Ch(..) => SortKey::Ch, - FontRelativeLength::Em(..) => SortKey::Em, - FontRelativeLength::Ex(..) => SortKey::Ex, - FontRelativeLength::Rem(..) => SortKey::Rem, - } - }, - NoCalcLength::ViewportPercentage(ref vp) => { - match *vp { - ViewportPercentageLength::Vh(..) => SortKey::Vh, - ViewportPercentageLength::Vw(..) => SortKey::Vw, - ViewportPercentageLength::Vmax(..) => SortKey::Vmax, - ViewportPercentageLength::Vmin(..) => SortKey::Vmin, - } - }, - NoCalcLength::ServoCharacterWidth(..) => unreachable!(), - } + Self::Length(ref l) => match *l { + NoCalcLength::Absolute(..) => SortKey::Px, + NoCalcLength::FontRelative(ref relative) => match *relative { + FontRelativeLength::Ch(..) => SortKey::Ch, + FontRelativeLength::Em(..) => SortKey::Em, + FontRelativeLength::Ex(..) => SortKey::Ex, + FontRelativeLength::Rem(..) => SortKey::Rem, + }, + NoCalcLength::ViewportPercentage(ref vp) => match *vp { + ViewportPercentageLength::Vh(..) => SortKey::Vh, + ViewportPercentageLength::Vw(..) => SortKey::Vw, + ViewportPercentageLength::Vmax(..) => SortKey::Vmax, + ViewportPercentageLength::Vmin(..) => SortKey::Vmin, + }, + NoCalcLength::ServoCharacterWidth(..) => unreachable!(), }, Self::Sum(..) | Self::MinMax(..) | Self::Clamp { .. } => SortKey::Other, } @@ -375,22 +377,28 @@ impl CalcNode { /// /// Only handles leaf nodes, it's the caller's responsibility to simplify /// them before calling this if needed. - fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()> { use - self::CalcNode::*; + fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()> { + use self::CalcNode::*; - match (self, other) { (&mut Number(ref mut one), &Number(ref other)) | - (&mut Percentage(ref mut one), &Percentage(ref other)) => { *one += - *other; } (&mut Angle(ref mut one), &Angle(ref other)) => { *one - = specified::Angle::from_calc(one.degrees() + - other.degrees()); } (&mut Time(ref mut one), &Time(ref - other)) => { *one = - specified::Time::from_calc(one.seconds() + - other.seconds()); } (&mut Length(ref mut one), - &Length(ref other)) => { *one = - one.try_sum(other)?; } _ => return Err(()), + match (self, other) { + (&mut Number(ref mut one), &Number(ref other)) | + (&mut Percentage(ref mut one), &Percentage(ref other)) => { + *one += *other; + }, + (&mut Angle(ref mut one), &Angle(ref other)) => { + *one = specified::Angle::from_calc(one.degrees() + other.degrees()); + }, + (&mut Time(ref mut one), &Time(ref other)) => { + *one = specified::Time::from_calc(one.seconds() + other.seconds()); + }, + (&mut Length(ref mut one), &Length(ref other)) => { + *one = one.try_sum(other)?; + }, + _ => return Err(()), } - Ok(()) } + Ok(()) + } /// Simplifies and sorts the calculation. This is only needed if it's going /// to be preserved after parsing (so, for ``). Otherwise @@ -401,10 +409,14 @@ impl CalcNode { ($slot:expr) => {{ let result = mem::replace($slot, Self::Number(0.)); mem::replace(self, result); - }} + }}; } match *self { - Self::Clamp { ref mut min, ref mut center, ref mut max } => { + Self::Clamp { + ref mut min, + ref mut center, + ref mut max, + } => { min.simplify_and_sort_children(); center.simplify_and_sort_children(); max.simplify_and_sort_children(); @@ -518,10 +530,7 @@ impl CalcNode { } } - debug_assert!( - children.len() >= 2, - "Should still have multiple kids!" - ); + debug_assert!(children.len() >= 2, "Should still have multiple kids!"); // Sort by spec order. children.sort_unstable_by_key(|c| c.calc_node_sort_key()); @@ -542,11 +551,8 @@ impl CalcNode { if let NoCalcLength::Absolute(ref mut absolute_length) = *len { *absolute_length = AbsoluteLength::Px(absolute_length.to_px()); } - } - Self::Percentage(..) | - Self::Angle(..) | - Self::Time(..) | - Self::Number(..) => { + }, + Self::Percentage(..) | Self::Angle(..) | Self::Time(..) | Self::Number(..) => { // These are leaves already, nothing to do. }, } @@ -604,11 +610,9 @@ impl CalcNode { (&Token::Percentage { unit_value, .. }, CalcUnit::Percentage) => { Ok(CalcNode::Percentage(unit_value)) }, - (&Token::ParenthesisBlock, _) => { - input.parse_nested_block(|input| { - CalcNode::parse_argument(context, input, expected_unit) - }) - }, + (&Token::ParenthesisBlock, _) => input.parse_nested_block(|input| { + CalcNode::parse_argument(context, input, expected_unit) + }), (&Token::Function(ref name), _) => { let function = CalcNode::math_function(name, location)?; CalcNode::parse(context, input, function, expected_unit) @@ -644,16 +648,17 @@ impl CalcNode { max: Box::new(max), }) }, - MathFunction::Min | - MathFunction::Max => { + MathFunction::Min | MathFunction::Max => { // TODO(emilio): The common case for parse_comma_separated // is just one element, but for min / max is two, really... // // Consider adding an API to cssparser to specify the // initial vector capacity? - let arguments = input.parse_comma_separated(|input| { - Self::parse_argument(context, input, expected_unit) - })?.into_boxed_slice(); + let arguments = input + .parse_comma_separated(|input| { + Self::parse_argument(context, input, expected_unit) + })? + .into_boxed_slice(); let op = match function { MathFunction::Min => MinMaxOp::Min, @@ -662,7 +667,7 @@ impl CalcNode { }; Ok(Self::MinMax(arguments, op)) - } + }, } }) } @@ -751,7 +756,9 @@ impl CalcNode { let number = match rhs.to_number() { Ok(n) if n != 0. => n, _ => { - return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError)); + return Err( + input.new_custom_error(StyleParseErrorKind::UnspecifiedError) + ); }, }; node.mul_by(1. / number); @@ -838,10 +845,9 @@ impl CalcNode { child.add_length_or_percentage_to(ret, factor)?; } }, - CalcNode::MinMax(..) | - CalcNode::Clamp { .. } => { + CalcNode::MinMax(..) | CalcNode::Clamp { .. } => { // FIXME(emilio): Implement min/max/clamp for length-percentage. - return Err(()) + return Err(()); }, CalcNode::Angle(..) | CalcNode::Time(..) | CalcNode::Number(..) => return Err(()), } diff --git a/components/style/values/specified/length.rs b/components/style/values/specified/length.rs index 3b971b422c2..ff24404c09a 100644 --- a/components/style/values/specified/length.rs +++ b/components/style/values/specified/length.rs @@ -111,7 +111,9 @@ impl FontRelativeLength { // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { - match *self { Em(..) | Ex(..) | Ch(..) | Rem(..) => {} } + match *self { + Em(..) | Ex(..) | Ch(..) | Rem(..) => {}, + } debug_unreachable!("Forgot to handle unit in try_sum()") }, }) @@ -283,7 +285,9 @@ impl ViewportPercentageLength { // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { - match *self { Vw(..) | Vh(..) | Vmin(..) | Vmax(..) => {} } + match *self { + Vw(..) | Vh(..) | Vmin(..) | Vmax(..) => {}, + } debug_unreachable!("Forgot to handle unit in try_sum()") }, }) @@ -527,14 +531,21 @@ impl NoCalcLength { Ok(match (self, other) { (&Absolute(ref one), &Absolute(ref other)) => Absolute(*one + *other), (&FontRelative(ref one), &FontRelative(ref other)) => FontRelative(one.try_sum(other)?), - (&ViewportPercentage(ref one), &ViewportPercentage(ref other)) => ViewportPercentage(one.try_sum(other)?), + (&ViewportPercentage(ref one), &ViewportPercentage(ref other)) => { + ViewportPercentage(one.try_sum(other)?) + }, (&ServoCharacterWidth(ref one), &ServoCharacterWidth(ref other)) => { ServoCharacterWidth(CharacterWidth(one.0 + other.0)) }, // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { - match *self { Absolute(..) | FontRelative(..) | ViewportPercentage(..) | ServoCharacterWidth(..) => {} } + match *self { + Absolute(..) | + FontRelative(..) | + ViewportPercentage(..) | + ServoCharacterWidth(..) => {}, + } debug_unreachable!("Forgot to handle unit in try_sum()") }, }) @@ -569,12 +580,21 @@ impl PartialOrd for NoCalcLength { match (self, other) { (&Absolute(ref one), &Absolute(ref other)) => one.to_px().partial_cmp(&other.to_px()), (&FontRelative(ref one), &FontRelative(ref other)) => one.partial_cmp(other), - (&ViewportPercentage(ref one), &ViewportPercentage(ref other)) => one.partial_cmp(other), - (&ServoCharacterWidth(ref one), &ServoCharacterWidth(ref other)) => one.0.partial_cmp(&other.0), + (&ViewportPercentage(ref one), &ViewportPercentage(ref other)) => { + one.partial_cmp(other) + }, + (&ServoCharacterWidth(ref one), &ServoCharacterWidth(ref other)) => { + one.0.partial_cmp(&other.0) + }, // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { - match *self { Absolute(..) | FontRelative(..) | ViewportPercentage(..) | ServoCharacterWidth(..) => {} } + match *self { + Absolute(..) | + FontRelative(..) | + ViewportPercentage(..) | + ServoCharacterWidth(..) => {}, + } debug_unreachable!("Forgot an arm in partial_cmp?") }, } @@ -645,7 +665,9 @@ impl PartialOrd for FontRelativeLength { // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { - match *self { Em(..) | Ex(..) | Ch(..) | Rem(..) => {} } + match *self { + Em(..) | Ex(..) | Ch(..) | Rem(..) => {}, + } debug_unreachable!("Forgot an arm in partial_cmp?") }, } @@ -696,7 +718,9 @@ impl PartialOrd for ViewportPercentageLength { // See https://github.com/rust-lang/rust/issues/68867. rustc isn't // able to figure it own on its own so we help. _ => unsafe { - match *self { Vw(..) | Vh(..) | Vmin(..) | Vmax(..) => {} } + match *self { + Vw(..) | Vh(..) | Vmin(..) | Vmax(..) => {}, + } debug_unreachable!("Forgot an arm in partial_cmp?") }, } @@ -957,7 +981,8 @@ impl LengthPercentage { }, Token::Function(ref name) => { let function = CalcNode::math_function(name, location)?; - let calc = CalcNode::parse_length_or_percentage(context, input, num_context, function)?; + let calc = + CalcNode::parse_length_or_percentage(context, input, num_context, function)?; Ok(LengthPercentage::Calc(Box::new(calc))) }, _ => return Err(location.new_unexpected_token_error(token.clone())), diff --git a/components/style/values/specified/mod.rs b/components/style/values/specified/mod.rs index 2d8160b17b9..54401045809 100644 --- a/components/style/values/specified/mod.rs +++ b/components/style/values/specified/mod.rs @@ -31,7 +31,7 @@ use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, StyleParseErrorKin pub use self::align::{AlignContent, AlignItems, AlignSelf, ContentDistribution}; #[cfg(feature = "gecko")] pub use self::align::{JustifyContent, JustifyItems, JustifySelf, SelfAlignment}; -pub use self::angle::{Angle, AllowUnitlessZeroAngle}; +pub use self::angle::{AllowUnitlessZeroAngle, Angle}; pub use self::background::{BackgroundRepeat, BackgroundSize}; pub use self::basic_shape::FillRule; pub use self::border::{BorderCornerRadius, BorderImageSlice, BorderImageWidth}; diff --git a/components/style/values/specified/position.rs b/components/style/values/specified/position.rs index d599d6a85d9..3f01988e49d 100644 --- a/components/style/values/specified/position.rs +++ b/components/style/values/specified/position.rs @@ -22,8 +22,8 @@ use cssparser::Parser; use selectors::parser::SelectorParseErrorKind; use servo_arc::Arc; use std::fmt::{self, Write}; -use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; use style_traits::values::specified::AllowedNumericType; +use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss}; /// The specified value of a CSS `` pub type Position = GenericPosition;