Bug 1517511, bug 1518098 - followup: Rustfmt so Servo's lints are happy.

This commit is contained in:
Emilio Cobos Álvarez 2019-01-07 16:57:43 +01:00
parent a66b31c93c
commit ee2d827d48
14 changed files with 85 additions and 98 deletions

View File

@ -80,8 +80,8 @@ impl From<nsStyleCoord_CalcValue> for LengthPercentageOrAuto {
// disappear as we move more stuff to cbindgen.
impl From<nsStyleCoord_CalcValue> for NonNegativeLengthPercentageOrAuto {
fn from(other: nsStyleCoord_CalcValue) -> Self {
NonNegative(
LengthPercentageOrAuto::LengthPercentage(LengthPercentage::with_clamping_mode(
NonNegative(LengthPercentageOrAuto::LengthPercentage(
LengthPercentage::with_clamping_mode(
Au(other.mLength).into(),
if other.mHasPercent {
Some(Percentage(other.mPercent))
@ -90,8 +90,8 @@ impl From<nsStyleCoord_CalcValue> for NonNegativeLengthPercentageOrAuto {
},
AllowedNumericType::NonNegative,
/* was_calc = */ true,
))
)
),
))
}
}
@ -529,17 +529,15 @@ impl nsStyleImage {
structs::NS_STYLE_GRADIENT_SHAPE_ELLIPTICAL => {
let length_percentage_keyword = match gecko_gradient.mSize as u32 {
structs::NS_STYLE_GRADIENT_SIZE_EXPLICIT_SIZE => match (
LengthPercentage::from_gecko_style_coord(
&gecko_gradient.mRadiusX,
),
LengthPercentage::from_gecko_style_coord(
&gecko_gradient.mRadiusY,
),
LengthPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusX),
LengthPercentage::from_gecko_style_coord(&gecko_gradient.mRadiusY),
) {
(Some(x), Some(y)) => Ellipse::Radii(x, y),
_ => {
debug_assert!(false,
"mRadiusX, mRadiusY could not convert to LengthPercentage");
debug_assert!(
false,
"mRadiusX, mRadiusY could not convert to LengthPercentage"
);
Ellipse::Radii(
LengthPercentage::zero(),
LengthPercentage::zero(),
@ -802,10 +800,9 @@ pub mod basic_shape {
),
),
NonNegative(
LengthPercentage::from_gecko_style_coord(&other.data_at(index + 1))
.expect(
"<border-radius> should be a length, percentage, or calc value",
),
LengthPercentage::from_gecko_style_coord(&other.data_at(index + 1)).expect(
"<border-radius> should be a length, percentage, or calc value",
),
),
)
};

View File

@ -149,7 +149,7 @@ impl GeckoStyleCoordConvertible for NumberOrPercentage {
impl GeckoStyleCoordConvertible for LengthPercentage {
fn to_gecko_style_coord<T: CoordDataMut>(&self, coord: &mut T) {
if self.was_calc {
return coord.set_value(CoordDataValue::Calc((*self).into()))
return coord.set_value(CoordDataValue::Calc((*self).into()));
}
debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero());
if let Some(p) = self.percentage {
@ -161,7 +161,9 @@ impl GeckoStyleCoordConvertible for LengthPercentage {
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
match coord.as_value() {
CoordDataValue::Coord(coord) => Some(LengthPercentage::new(Au(coord).into(), None)),
CoordDataValue::Percent(p) => Some(LengthPercentage::new(Au(0).into(), Some(Percentage(p)))),
CoordDataValue::Percent(p) => {
Some(LengthPercentage::new(Au(0).into(), Some(Percentage(p))))
},
CoordDataValue::Calc(calc) => Some(calc.into()),
_ => None,
}
@ -192,7 +194,8 @@ impl GeckoStyleCoordConvertible for LengthPercentageOrAuto {
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
match coord.as_value() {
CoordDataValue::Auto => Some(LengthPercentageOrAuto::Auto),
_ => LengthPercentage::from_gecko_style_coord(coord).map(LengthPercentageOrAuto::LengthPercentage),
_ => LengthPercentage::from_gecko_style_coord(coord)
.map(LengthPercentageOrAuto::LengthPercentage),
}
}
}
@ -208,7 +211,8 @@ impl GeckoStyleCoordConvertible for LengthPercentageOrNone {
fn from_gecko_style_coord<T: CoordData>(coord: &T) -> Option<Self> {
match coord.as_value() {
CoordDataValue::None => Some(LengthPercentageOrNone::None),
_ => LengthPercentage::from_gecko_style_coord(coord).map(LengthPercentageOrNone::LengthPercentage),
_ => LengthPercentage::from_gecko_style_coord(coord)
.map(LengthPercentageOrNone::LengthPercentage),
}
}
}

View File

@ -70,7 +70,7 @@ impl nsCSSValue {
/// Sets LengthPercentage value to this nsCSSValue.
pub unsafe fn set_length_percentage(&mut self, lp: LengthPercentage) {
if lp.was_calc {
return bindings::Gecko_CSSValue_SetCalc(self, lp.into())
return bindings::Gecko_CSSValue_SetCalc(self, lp.into());
}
debug_assert!(lp.percentage.is_none() || lp.unclamped_length() == Length::zero());
if let Some(p) = lp.percentage {
@ -93,17 +93,12 @@ impl nsCSSValue {
pub unsafe fn get_length_percentage(&self) -> LengthPercentage {
match self.mUnit {
nsCSSUnit::eCSSUnit_Pixel => {
LengthPercentage::new(
Length::new(bindings::Gecko_CSSValue_GetNumber(self)),
None,
)
LengthPercentage::new(Length::new(bindings::Gecko_CSSValue_GetNumber(self)), None)
},
nsCSSUnit::eCSSUnit_Percent => LengthPercentage::new_percent(Percentage(
bindings::Gecko_CSSValue_GetPercentage(self),
)),
nsCSSUnit::eCSSUnit_Calc => {
bindings::Gecko_CSSValue_GetCalc(self).into()
},
nsCSSUnit::eCSSUnit_Calc => bindings::Gecko_CSSValue_GetCalc(self).into(),
_ => panic!("Unexpected unit"),
}
}

View File

@ -18,7 +18,9 @@ use crate::shared_lock::{SharedRwLockReadGuard, StylesheetGuards, ToCssWithGuard
use crate::str::CssStringWriter;
use crate::stylesheets::{Origin, StylesheetInDocument};
use crate::values::computed::{Context, ToComputedValue};
use crate::values::specified::{self, LengthPercentageOrAuto, NoCalcLength, ViewportPercentageLength};
use crate::values::specified::{
self, LengthPercentageOrAuto, NoCalcLength, ViewportPercentageLength,
};
use app_units::Au;
use cssparser::CowRcStr;
use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
@ -158,7 +160,7 @@ impl FromMeta for ViewportLength {
macro_rules! specified {
($value:expr) => {
ViewportLength::Specified(LengthPercentageOrAuto::LengthPercentage(
specified::LengthPercentage::Length($value)
specified::LengthPercentage::Length($value),
))
};
}
@ -755,9 +757,10 @@ impl MaybeNew for ViewportConstraints {
match *$value {
ViewportLength::Specified(ref length) => match *length {
LengthPercentageOrAuto::Auto => None,
LengthPercentageOrAuto::LengthPercentage(ref lop) => Some(lop
.to_computed_value(&context)
.to_used_value(initial_viewport.$dimension)),
LengthPercentageOrAuto::LengthPercentage(ref lop) => Some(
lop.to_computed_value(&context)
.to_used_value(initial_viewport.$dimension),
),
},
ViewportLength::ExtendToZoom => {
// $extend_to will be 'None' if 'extend-to-zoom' is 'auto'

View File

@ -27,7 +27,9 @@ impl Animate for LengthPercentage {
.unclamped_length()
.animate(&other.unclamped_length(), procedure)?;
let percentage = animate_percentage_half(self.percentage, other.percentage)?;
let is_calc = self.was_calc || other.was_calc || self.percentage.is_some() != other.percentage.is_some();
let is_calc = self.was_calc ||
other.was_calc ||
self.percentage.is_some() != other.percentage.is_some();
Ok(Self::with_clamping_mode(
length,
percentage,

View File

@ -32,16 +32,14 @@ fn to_number_or_percentage(
value: &SvgLengthPercentageOrNumber<LengthPercentage, Number>,
) -> Result<NumberOrPercentage, ()> {
Ok(match *value {
SvgLengthPercentageOrNumber::LengthPercentage(ref l) => {
match l.percentage {
Some(p) => {
if l.unclamped_length().px() != 0. {
return Err(());
}
NumberOrPercentage::Percentage(p)
SvgLengthPercentageOrNumber::LengthPercentage(ref l) => match l.percentage {
Some(p) => {
if l.unclamped_length().px() != 0. {
return Err(());
}
None => NumberOrPercentage::Number(l.length().px())
}
NumberOrPercentage::Percentage(p)
},
None => NumberOrPercentage::Number(l.length().px()),
},
SvgLengthPercentageOrNumber::Number(ref n) => NumberOrPercentage::Number(*n),
})

View File

@ -34,8 +34,7 @@ pub type BasicShape = generic::BasicShape<
pub type InsetRect = generic::InsetRect<LengthPercentage, NonNegativeLengthPercentage>;
/// A computed circle.
pub type Circle =
generic::Circle<LengthPercentage, LengthPercentage, NonNegativeLengthPercentage>;
pub type Circle = generic::Circle<LengthPercentage, LengthPercentage, NonNegativeLengthPercentage>;
/// A computed ellipse.
pub type Ellipse =

View File

@ -71,10 +71,16 @@ impl generic::LineDirection for LineDirection {
LineDirection::Vertical(Y::Top) if compat_mode != CompatMode::Modern => true,
LineDirection::Corner(..) => false,
#[cfg(feature = "gecko")]
LineDirection::MozPosition(Some(Position { ref vertical, ref horizontal }), None) => {
LineDirection::MozPosition(
Some(Position {
ref vertical,
ref horizontal,
}),
None,
) => {
// `50% 0%` is the default value for line direction.
horizontal.as_percentage().map_or(false, |p| p.0 == 0.5) &&
vertical.as_percentage().map_or(false, |p| p.0 == 0.0)
vertical.as_percentage().map_or(false, |p| p.0 == 0.0)
},
_ => false,
}

View File

@ -5,7 +5,7 @@
//! `<length>` computed values, and related ones.
use super::{Context, Number, Percentage, ToComputedValue};
use crate::values::animated::{ToAnimatedValue};
use crate::values::animated::ToAnimatedValue;
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
use crate::values::generics::length::MaxLength as GenericMaxLength;
use crate::values::generics::length::MozLength as GenericMozLength;
@ -170,7 +170,6 @@ impl LengthPercentage {
self.length
}
/// Return the percentage value as CSSFloat.
#[inline]
pub fn percentage(&self) -> CSSFloat {
@ -380,7 +379,7 @@ impl LengthPercentage {
self.percentage,
AllowedNumericType::NonNegative,
self.was_calc,
)
);
}
debug_assert!(self.percentage.is_none() || self.unclamped_length() == Length::zero());
@ -410,32 +409,25 @@ impl ToComputedValue for specified::LengthPercentage {
specified::LengthPercentage::Length(ref value) => {
LengthPercentage::new(value.to_computed_value(context), None)
},
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),
}
}
fn from_computed_value(computed: &LengthPercentage) -> Self {
let length = computed.unclamped_length();
if let Some(p) = computed.as_percentage() {
return specified::LengthPercentage::Percentage(p)
return specified::LengthPercentage::Percentage(p);
}
let percentage = computed.percentage;
if percentage.is_none() &&
computed.clamping_mode.clamp(length.px()) == length.px() {
return specified::LengthPercentage::Length(
ToComputedValue::from_computed_value(&length)
)
if percentage.is_none() && computed.clamping_mode.clamp(length.px()) == length.px() {
return specified::LengthPercentage::Length(ToComputedValue::from_computed_value(
&length,
));
}
specified::LengthPercentage::Calc(Box::new(
ToComputedValue::from_computed_value(computed),
))
specified::LengthPercentage::Calc(Box::new(ToComputedValue::from_computed_value(computed)))
}
}
@ -448,7 +440,9 @@ impl IsZeroLength for LengthPercentage {
#[allow(missing_docs)]
#[css(derive_debug)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)]
#[derive(
Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss,
)]
pub enum LengthPercentageOrAuto {
LengthPercentage(LengthPercentage),
Auto,
@ -522,9 +516,7 @@ impl ToComputedValue for specified::LengthPercentageOrAuto {
fn to_computed_value(&self, context: &Context) -> LengthPercentageOrAuto {
match *self {
specified::LengthPercentageOrAuto::LengthPercentage(ref value) => {
LengthPercentageOrAuto::LengthPercentage(
value.to_computed_value(context),
)
LengthPercentageOrAuto::LengthPercentage(value.to_computed_value(context))
},
specified::LengthPercentageOrAuto::Auto => LengthPercentageOrAuto::Auto,
}
@ -545,7 +537,9 @@ impl ToComputedValue for specified::LengthPercentageOrAuto {
#[allow(missing_docs)]
#[css(derive_debug)]
#[derive(Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss)]
#[derive(
Animate, Clone, ComputeSquaredDistance, Copy, MallocSizeOf, PartialEq, ToAnimatedZero, ToCss,
)]
pub enum LengthPercentageOrNone {
LengthPercentage(LengthPercentage),
None,

View File

@ -191,8 +191,7 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthPercentage> {
#[allow(missing_docs)]
#[css(comma, function = "interpolatematrix")]
InterpolateMatrix {
from_list:
Transform<TransformOperation<Angle, Number, Length, Integer, LengthPercentage>>,
from_list: Transform<TransformOperation<Angle, Number, Length, Integer, LengthPercentage>>,
to_list: Transform<TransformOperation<Angle, Number, Length, Integer, LengthPercentage>>,
progress: computed::Percentage,
},
@ -200,8 +199,7 @@ pub enum TransformOperation<Angle, Number, Length, Integer, LengthPercentage> {
#[allow(missing_docs)]
#[css(comma, function = "accumulatematrix")]
AccumulateMatrix {
from_list:
Transform<TransformOperation<Angle, Number, Length, Integer, LengthPercentage>>,
from_list: Transform<TransformOperation<Angle, Number, Length, Integer, LengthPercentage>>,
to_list: Transform<TransformOperation<Angle, Number, Length, Integer, LengthPercentage>>,
count: Integer,
},

View File

@ -278,8 +278,7 @@ impl Parse for VerticalAlign {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
if let Ok(lp) =
input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes))
if let Ok(lp) = input.try(|i| LengthPercentage::parse_quirky(context, i, AllowQuirks::Yes))
{
return Ok(GenericVerticalAlign::Length(lp));
}

View File

@ -73,8 +73,7 @@ impl Parse for TrackSize<LengthPercentage> {
}
input.expect_function_matching("fit-content")?;
let lp =
input.parse_nested_block(|i| LengthPercentage::parse_non_negative(context, i))?;
let lp = input.parse_nested_block(|i| LengthPercentage::parse_non_negative(context, i))?;
Ok(TrackSize::FitContent(lp))
}
}

View File

@ -698,16 +698,16 @@ impl generic::LineDirection for LineDirection {
// These percentage values can also be keywords.
let x = match *x {
OriginComponent::Center => true,
OriginComponent::Length(LengthPercentage::Percentage(
ComputedPercentage(val),
)) => val == 0.5,
OriginComponent::Length(LengthPercentage::Percentage(ComputedPercentage(
val,
))) => val == 0.5,
_ => false,
};
let y = match *y {
OriginComponent::Side(Y::Top) => true,
OriginComponent::Length(LengthPercentage::Percentage(
ComputedPercentage(val),
)) => val == 0.0,
OriginComponent::Length(LengthPercentage::Percentage(ComputedPercentage(
val,
))) => val == 0.0,
_ => false,
};
x && y

View File

@ -922,12 +922,9 @@ impl LengthPercentageOrAuto {
return Ok(LengthPercentageOrAuto::Auto);
}
Ok(LengthPercentageOrAuto::LengthPercentage(LengthPercentage::parse_internal(
context,
input,
num_context,
allow_quirks,
)?))
Ok(LengthPercentageOrAuto::LengthPercentage(
LengthPercentage::parse_internal(context, input, num_context, allow_quirks)?,
))
}
/// Parse a non-negative length, percentage, or auto.
@ -1052,12 +1049,9 @@ impl LengthPercentageOrNone {
return Ok(LengthPercentageOrNone::None);
}
Ok(LengthPercentageOrNone::LengthPercentage(LengthPercentage::parse_internal(
context,
input,
num_context,
allow_quirks,
)?))
Ok(LengthPercentageOrNone::LengthPercentage(
LengthPercentage::parse_internal(context, input, num_context, allow_quirks)?,
))
}
/// Parse a non-negative LengthPercentageOrNone.
@ -1117,8 +1111,7 @@ impl Parse for NonNegativeLengthPercentage {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
LengthPercentage::parse_non_negative(context, input)
.map(NonNegative::<LengthPercentage>)
LengthPercentage::parse_non_negative(context, input).map(NonNegative::<LengthPercentage>)
}
}