style: Run "cargo +nightly fmt" for style components in servo

The directories changed:
* servo/components/selectors/
* servo/components/style/
* servo/components/style_derive/
* servo/ports/geckolib/

Per review request, disable rustfmt in `components_to_transform_3d_matrix()` to
preserve the format for a call to `Transform3D::new`.

My mozilla-central is at
https://hg.mozilla.org/mozilla-central/rev/d1ae84015c22f2034435b47194fdced878072035

My nightly rust is 1.66.0-nightly (8b705839c 2022-09-26).

Differential Revision: https://phabricator.services.mozilla.com/D158234
This commit is contained in:
Ting-Yu Lin 2022-09-28 07:10:52 +00:00 committed by Martin Robinson
parent 1a9198a5ef
commit 3da52edffc
60 changed files with 684 additions and 489 deletions

View file

@ -8,7 +8,9 @@ use crate::values::animated::{Animate, Procedure};
use crate::values::computed::length::{LengthPercentage, NonNegativeLength};
use crate::values::computed::{Context, Integer, Number, ToComputedValue};
use crate::values::generics::box_::AnimationIterationCount as GenericAnimationIterationCount;
use crate::values::generics::box_::{GenericLineClamp, GenericPerspective, GenericVerticalAlign, GenericContainIntrinsicSize};
use crate::values::generics::box_::{
GenericContainIntrinsicSize, GenericLineClamp, GenericPerspective, GenericVerticalAlign,
};
use crate::values::specified::box_ as specified;
pub use crate::values::specified::box_::{
@ -39,7 +41,7 @@ impl Animate for LineClamp {
return Err(());
}
if self.is_none() {
return Ok(Self::none())
return Ok(Self::none());
}
Ok(Self(self.0.animate(&other.0, procedure)?.max(1)))
}

View file

@ -6,8 +6,8 @@
use crate::values::animated::color::AnimatedRGBA;
use crate::values::animated::ToAnimatedValue;
use crate::values::generics::color::{GenericCaretColor, GenericColor, GenericColorOrAuto};
use crate::values::computed::percentage::Percentage;
use crate::values::generics::color::{GenericCaretColor, GenericColor, GenericColorOrAuto};
use cssparser::{Color as CSSParserColor, RGBA};
use std::fmt;
use style_traits::{CssWriter, ToCss};

View file

@ -7,8 +7,8 @@
use crate::parser::{Parse, ParserContext};
use crate::values::animated::ToAnimatedValue;
use crate::values::computed::{
Angle, Context, Integer, Length, NonNegativeLength, NonNegativeNumber,
Number, Percentage, ToComputedValue
Angle, Context, Integer, Length, NonNegativeLength, NonNegativeNumber, Number, Percentage,
ToComputedValue,
};
use crate::values::generics::font::{FeatureTagValue, FontSettings, VariationValue};
use crate::values::generics::{font as generics, NonNegative};
@ -48,7 +48,16 @@ pub use crate::values::specified::Integer as SpecifiedInteger;
/// cbindgen:derive-gte
#[repr(C)]
#[derive(
Clone, ComputeSquaredDistance, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Eq,
Hash,
MallocSizeOf,
PartialEq,
PartialOrd,
ToResolvedValue,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
pub struct FixedPoint<T, const FRACTION_BITS: u16> {
@ -96,7 +105,15 @@ pub type FontWeightFixedPoint = FixedPoint<u16, FONT_WEIGHT_FRACTION_BITS>;
/// cbindgen:derive-gt
/// cbindgen:derive-gte
#[derive(
Clone, ComputeSquaredDistance, Copy, Debug, Hash, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Hash,
MallocSizeOf,
PartialEq,
PartialOrd,
ToResolvedValue,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
@ -126,13 +143,19 @@ impl ToCss for FontWeight {
impl FontWeight {
/// The `normal` keyword.
pub const NORMAL: FontWeight = FontWeight(FontWeightFixedPoint { value: 400 << FONT_WEIGHT_FRACTION_BITS });
pub const NORMAL: FontWeight = FontWeight(FontWeightFixedPoint {
value: 400 << FONT_WEIGHT_FRACTION_BITS,
});
/// The `bold` value.
pub const BOLD: FontWeight = FontWeight(FontWeightFixedPoint { value: 700 << FONT_WEIGHT_FRACTION_BITS });
pub const BOLD: FontWeight = FontWeight(FontWeightFixedPoint {
value: 700 << FONT_WEIGHT_FRACTION_BITS,
});
/// The threshold from which we consider a font bold.
pub const BOLD_THRESHOLD: FontWeight = FontWeight(FontWeightFixedPoint { value: 600 << FONT_WEIGHT_FRACTION_BITS });
pub const BOLD_THRESHOLD: FontWeight = FontWeight(FontWeightFixedPoint {
value: 600 << FONT_WEIGHT_FRACTION_BITS,
});
/// Returns the `normal` keyword value.
pub fn normal() -> Self {
@ -151,7 +174,9 @@ impl FontWeight {
/// Construct a valid weight from a float value.
pub fn from_float(v: f32) -> Self {
Self(FixedPoint::from_float(v.max(MIN_FONT_WEIGHT).min(MAX_FONT_WEIGHT)))
Self(FixedPoint::from_float(
v.max(MIN_FONT_WEIGHT).min(MAX_FONT_WEIGHT),
))
}
/// Return the bolder weight.
@ -176,7 +201,7 @@ impl FontWeight {
pub fn lighter(self) -> Self {
let value = self.value();
if value < 550. {
return Self::from_float(value.min(100.))
return Self::from_float(value.min(100.));
}
if value < 750. {
return Self::NORMAL;
@ -902,7 +927,16 @@ pub type FontStyleFixedPoint = FixedPoint<i16, FONT_STYLE_FRACTION_BITS>;
/// cbindgen:derive-gt
/// cbindgen:derive-gte
#[derive(
Clone, ComputeSquaredDistance, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, PartialOrd, ToResolvedValue,
Clone,
ComputeSquaredDistance,
Copy,
Debug,
Eq,
Hash,
MallocSizeOf,
PartialEq,
PartialOrd,
ToResolvedValue,
)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(C)]
@ -910,16 +944,22 @@ pub struct FontStyle(FontStyleFixedPoint);
impl FontStyle {
/// The normal keyword.
pub const NORMAL: FontStyle = FontStyle(FontStyleFixedPoint { value: 100 << FONT_STYLE_FRACTION_BITS });
pub const NORMAL: FontStyle = FontStyle(FontStyleFixedPoint {
value: 100 << FONT_STYLE_FRACTION_BITS,
});
/// The italic keyword.
pub const ITALIC: FontStyle = FontStyle(FontStyleFixedPoint { value: 101 << FONT_STYLE_FRACTION_BITS });
pub const ITALIC: FontStyle = FontStyle(FontStyleFixedPoint {
value: 101 << FONT_STYLE_FRACTION_BITS,
});
/// The default angle for `font-style: oblique`.
/// See also https://github.com/w3c/csswg-drafts/issues/2295
pub const DEFAULT_OBLIQUE_DEGREES: i16 = 14;
/// The `oblique` keyword with the default degrees.
pub const OBLIQUE: FontStyle = FontStyle(FontStyleFixedPoint { value: Self::DEFAULT_OBLIQUE_DEGREES << FONT_STYLE_FRACTION_BITS });
pub const OBLIQUE: FontStyle = FontStyle(FontStyleFixedPoint {
value: Self::DEFAULT_OBLIQUE_DEGREES << FONT_STYLE_FRACTION_BITS,
});
/// The `normal` value.
#[inline]
@ -932,7 +972,7 @@ impl FontStyle {
Self(FixedPoint::from_float(
degrees
.max(specified::FONT_STYLE_OBLIQUE_MIN_ANGLE_DEGREES)
.min(specified::FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES)
.min(specified::FONT_STYLE_OBLIQUE_MAX_ANGLE_DEGREES),
))
}
@ -950,10 +990,10 @@ impl ToCss for FontStyle {
W: fmt::Write,
{
if *self == Self::NORMAL {
return dest.write_str("normal")
return dest.write_str("normal");
}
if *self == Self::ITALIC {
return dest.write_str("italic")
return dest.write_str("italic");
}
if *self == Self::OBLIQUE {
return dest.write_str("oblique");
@ -971,10 +1011,10 @@ impl ToAnimatedValue for FontStyle {
#[inline]
fn to_animated_value(self) -> Self::AnimatedValue {
if self == Self::NORMAL {
return generics::FontStyle::Normal
return generics::FontStyle::Normal;
}
if self == Self::ITALIC {
return generics::FontStyle::Italic
return generics::FontStyle::Italic;
}
generics::FontStyle::Oblique(Angle::from_degrees(self.oblique_degrees()))
}
@ -989,7 +1029,6 @@ impl ToAnimatedValue for FontStyle {
}
}
/// font-stretch is a percentage relative to normal.
///
/// We use an unsigned 10.6 fixed-point value (range 0.0 - 1023.984375)
@ -1002,7 +1041,6 @@ pub const FONT_STRETCH_FRACTION_BITS: u16 = 6;
/// workaround.
pub type FontStretchFixedPoint = FixedPoint<u16, FONT_STRETCH_FRACTION_BITS>;
/// A value for the font-stretch property per:
///
/// https://drafts.csswg.org/css-fonts-4/#propdef-font-stretch
@ -1025,23 +1063,41 @@ impl FontStretch {
pub const HALF: u16 = 1 << (Self::FRACTION_BITS - 1);
/// The `ultra-condensed` keyword.
pub const ULTRA_CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint { value: 50 << Self::FRACTION_BITS });
pub const ULTRA_CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint {
value: 50 << Self::FRACTION_BITS,
});
/// The `extra-condensed` keyword.
pub const EXTRA_CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint { value: (62 << Self::FRACTION_BITS) + Self::HALF });
pub const EXTRA_CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint {
value: (62 << Self::FRACTION_BITS) + Self::HALF,
});
/// The `condensed` keyword.
pub const CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint { value: 75 << Self::FRACTION_BITS });
pub const CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint {
value: 75 << Self::FRACTION_BITS,
});
/// The `semi-condensed` keyword.
pub const SEMI_CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint { value: (87 << Self::FRACTION_BITS) + Self::HALF });
pub const SEMI_CONDENSED: FontStretch = FontStretch(FontStretchFixedPoint {
value: (87 << Self::FRACTION_BITS) + Self::HALF,
});
/// The `normal` keyword.
pub const NORMAL: FontStretch = FontStretch(FontStretchFixedPoint { value: 100 << Self::FRACTION_BITS });
pub const NORMAL: FontStretch = FontStretch(FontStretchFixedPoint {
value: 100 << Self::FRACTION_BITS,
});
/// The `semi-expanded` keyword.
pub const SEMI_EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint { value: (112 << Self::FRACTION_BITS) + Self::HALF });
pub const SEMI_EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint {
value: (112 << Self::FRACTION_BITS) + Self::HALF,
});
/// The `expanded` keyword.
pub const EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint { value: 125 << Self::FRACTION_BITS });
pub const EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint {
value: 125 << Self::FRACTION_BITS,
});
/// The `extra-expanded` keyword.
pub const EXTRA_EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint { value: 150 << Self::FRACTION_BITS });
pub const EXTRA_EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint {
value: 150 << Self::FRACTION_BITS,
});
/// The `ultra-expanded` keyword.
pub const ULTRA_EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint { value: 200 << Self::FRACTION_BITS });
pub const ULTRA_EXPANDED: FontStretch = FontStretch(FontStretchFixedPoint {
value: 200 << Self::FRACTION_BITS,
});
/// 100%
pub fn hundred() -> Self {

View file

@ -42,7 +42,11 @@ impl ToComputedValue for specified::NoCalcLength {
impl specified::NoCalcLength {
/// Computes a length with a given font-relative base size.
pub fn to_computed_value_with_base_size(&self, context: &Context, base_size: FontBaseSize) -> Length {
pub fn to_computed_value_with_base_size(
&self,
context: &Context,
base_size: FontBaseSize,
) -> Length {
match *self {
specified::NoCalcLength::Absolute(length) => length.to_computed_value(context),
specified::NoCalcLength::FontRelative(length) => {

View file

@ -762,11 +762,7 @@ impl specified::CalcLengthPercentage {
context: &Context,
base_size: FontBaseSize,
) -> LengthPercentage {
self.to_computed_value_with_zoom(
context,
|abs| context.maybe_zoom_text(abs),
base_size,
)
self.to_computed_value_with_zoom(context, |abs| context.maybe_zoom_text(abs), base_size)
}
/// Compute the value into pixel length as CSSFloat without context,

View file

@ -16,13 +16,13 @@ use super::specified;
use super::{CSSFloat, CSSInteger};
use crate::computed_value_flags::ComputedValueFlags;
use crate::context::QuirksMode;
use crate::stylesheets::container_rule::ContainerInfo;
use crate::font_metrics::{FontMetrics, FontMetricsOrientation};
use crate::media_queries::Device;
#[cfg(feature = "gecko")]
use crate::properties;
use crate::properties::{ComputedValues, LonghandId, StyleBuilder};
use crate::rule_cache::RuleCacheConditions;
use crate::stylesheets::container_rule::ContainerInfo;
use crate::values::specified::length::FontBaseSize;
use crate::{ArcSlice, Atom, One};
use euclid::{default, Point2D, Rect, Size2D};
@ -45,8 +45,13 @@ pub use self::basic_shape::FillRule;
pub use self::border::{BorderCornerRadius, BorderRadius, BorderSpacing};
pub use self::border::{BorderImageRepeat, BorderImageSideWidth};
pub use self::border::{BorderImageSlice, BorderImageWidth};
pub use self::box_::{AnimationIterationCount, AnimationName, AnimationTimeline, Contain, ContainerName, ContainerType};
pub use self::box_::{Appearance, BreakBetween, BreakWithin, Clear, ContentVisibility, ContainIntrinsicSize, Float};
pub use self::box_::{
AnimationIterationCount, AnimationName, AnimationTimeline, Contain, ContainerName,
ContainerType,
};
pub use self::box_::{
Appearance, BreakBetween, BreakWithin, Clear, ContainIntrinsicSize, ContentVisibility, Float,
};
pub use self::box_::{Display, LineClamp, Overflow, OverflowAnchor, TransitionProperty};
pub use self::box_::{OverflowClipBox, OverscrollBehavior, Perspective, Resize, ScrollbarGutter};
pub use self::box_::{ScrollAxis, ScrollSnapAlign, ScrollSnapAxis, ScrollSnapStop};
@ -74,7 +79,7 @@ pub use self::list::ListStyleType;
pub use self::list::Quotes;
pub use self::motion::{OffsetPath, OffsetRotate};
pub use self::outline::OutlineStyle;
pub use self::page::{PageOrientation, PageName, PageSize, PaperSize};
pub use self::page::{PageName, PageOrientation, PageSize, PaperSize};
pub use self::percentage::{NonNegativePercentage, Percentage};
pub use self::position::AspectRatio;
pub use self::position::{
@ -97,7 +102,7 @@ pub use self::transform::{Rotate, Scale, Transform, TransformOperation};
pub use self::transform::{TransformOrigin, TransformStyle, Translate};
#[cfg(feature = "gecko")]
pub use self::ui::CursorImage;
pub use self::ui::{Cursor, BoolInteger, UserSelect};
pub use self::ui::{BoolInteger, Cursor, UserSelect};
pub use super::specified::TextTransform;
pub use super::specified::ViewportVariant;
pub use super::specified::{BorderStyle, TextDecorationLine};
@ -339,10 +344,7 @@ pub struct ComputedVecIter<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> {
impl<'a, 'cx, 'cx_a: 'cx, S: ToComputedValue + 'a> ComputedVecIter<'a, 'cx, 'cx_a, S> {
/// Construct an iterator from a slice of specified values and a context
pub fn new(cx: &'cx Context<'cx_a>, values: &'a [S]) -> Self {
ComputedVecIter {
cx,
values,
}
ComputedVecIter { cx, values }
}
}