Run rustfmt on selectors, servo_arc, and style.

This was generated with:

./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style

Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
This commit is contained in:
Bobby Holley 2018-04-10 17:35:15 -07:00
parent f7ae1a37e3
commit c99bcdd4b8
181 changed files with 9981 additions and 7933 deletions

View file

@ -7,13 +7,13 @@
use app_units::AU_PER_PX;
use app_units::Au;
use context::QuirksMode;
use cssparser::{Parser, RGBA, Token, BasicParseErrorKind};
use cssparser::{BasicParseErrorKind, Parser, Token, RGBA};
use euclid::Size2D;
use euclid::TypedScale;
use gecko::values::{convert_nscolor_to_rgba, convert_rgba_to_nscolor};
use gecko_bindings::bindings;
use gecko_bindings::structs;
use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSValue, nsCSSUnit};
use gecko_bindings::structs::{nsCSSKeyword, nsCSSProps_KTableEntry, nsCSSUnit, nsCSSValue};
use gecko_bindings::structs::{nsMediaFeature, nsMediaFeature_RangeType};
use gecko_bindings::structs::{nsMediaFeature_ValueType, nsPresContext};
use gecko_bindings::structs::RawGeckoPresContextOwned;
@ -26,10 +26,10 @@ use std::sync::atomic::{AtomicBool, AtomicIsize, AtomicUsize, Ordering};
use str::starts_with_ignore_ascii_case;
use string_cache::Atom;
use style_traits::{CSSPixel, CssWriter, DevicePixel};
use style_traits::{ToCss, ParseError, StyleParseErrorKind};
use style_traits::{ParseError, StyleParseErrorKind, ToCss};
use style_traits::viewport::ViewportConstraints;
use stylesheets::Origin;
use values::{CSSFloat, CustomIdent, KeyframesName, serialize_atom_identifier};
use values::{serialize_atom_identifier, CSSFloat, CustomIdent, KeyframesName};
use values::computed::{self, ToComputedValue};
use values::computed::font::FontSize;
use values::specified::{Integer, Length, Number};
@ -84,10 +84,7 @@ impl Device {
/// Tells the device that a new viewport rule has been found, and stores the
/// relevant viewport constraints.
pub fn account_for_viewport_rule(
&mut self,
_constraints: &ViewportConstraints,
) {
pub fn account_for_viewport_rule(&mut self, _constraints: &ViewportConstraints) {
unreachable!("Gecko doesn't support @viewport");
}
@ -121,14 +118,16 @@ 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.
///
/// <https://quirks.spec.whatwg.org/#the-tables-inherit-color-from-body-quirk>
pub fn set_body_text_color(&self, color: RGBA) {
self.body_text_color.store(convert_rgba_to_nscolor(&color) as usize, Ordering::Relaxed)
self.body_text_color
.store(convert_rgba_to_nscolor(&color) as usize, Ordering::Relaxed)
}
/// Returns the body text color.
@ -201,7 +200,9 @@ impl Device {
/// Returns the device pixel ratio.
pub fn device_pixel_ratio(&self) -> TypedScale<f32, CSSPixel, DevicePixel> {
let override_dppx = self.pres_context().mOverrideDPPX;
if override_dppx > 0.0 { return TypedScale::new(override_dppx); }
if override_dppx > 0.0 {
return TypedScale::new(override_dppx);
}
let au_per_dpx = self.pres_context().mCurAppUnitsPerDevPixel as f32;
let au_per_px = AU_PER_PX as f32;
TypedScale::new(au_per_px / au_per_dpx)
@ -249,11 +250,13 @@ pub struct Expression {
impl ToCss for Expression {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
where W: fmt::Write,
where
W: fmt::Write,
{
dest.write_str("(")?;
if (self.feature.mReqFlags & structs::nsMediaFeature_RequirementFlags_eHasWebkitPrefix) != 0 {
if (self.feature.mReqFlags & structs::nsMediaFeature_RequirementFlags_eHasWebkitPrefix) != 0
{
dest.write_str("-webkit-")?;
}
match self.range {
@ -263,7 +266,9 @@ impl ToCss for Expression {
}
// NB: CssStringWriter not needed, feature names are under control.
write!(dest, "{}", unsafe { Atom::from_static(*self.feature.mName) })?;
write!(dest, "{}", unsafe {
Atom::from_static(*self.feature.mName)
})?;
if let Some(ref val) = self.value {
dest.write_str(": ")?;
@ -276,8 +281,8 @@ impl ToCss for Expression {
impl PartialEq for Expression {
fn eq(&self, other: &Expression) -> bool {
self.feature.mName == other.feature.mName &&
self.value == other.value && self.range == other.range
self.feature.mName == other.feature.mName && self.value == other.value &&
self.range == other.range
}
}
@ -307,14 +312,14 @@ impl Resolution {
fn parse<'i, 't>(input: &mut Parser<'i, 't>) -> Result<Self, ParseError<'i>> {
let location = input.current_source_location();
let (value, unit) = match *input.next()? {
Token::Dimension { value, ref unit, .. } => {
(value, unit)
},
Token::Dimension {
value, ref unit, ..
} => (value, unit),
ref t => return Err(location.new_unexpected_token_error(t.clone())),
};
if value <= 0. {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
(match_ignore_ascii_case! { &unit,
@ -322,7 +327,9 @@ impl Resolution {
"dppx" => Ok(Resolution::Dppx(value)),
"dpcm" => Ok(Resolution::Dpcm(value)),
_ => Err(())
}).map_err(|()| location.new_custom_error(StyleParseErrorKind::UnexpectedDimension(unit.clone())))
}).map_err(|()| {
location.new_custom_error(StyleParseErrorKind::UnexpectedDimension(unit.clone()))
})
}
}
@ -369,36 +376,38 @@ impl MediaExpressionValue {
debug_assert_eq!(css_value.mUnit, nsCSSUnit::eCSSUnit_Pixel);
let pixels = css_value.float_unchecked();
Some(MediaExpressionValue::Length(Length::from_px(pixels)))
}
},
nsMediaFeature_ValueType::eInteger => {
let i = css_value.integer_unchecked();
debug_assert!(i >= 0);
Some(MediaExpressionValue::Integer(i as u32))
}
},
nsMediaFeature_ValueType::eFloat => {
debug_assert_eq!(css_value.mUnit, nsCSSUnit::eCSSUnit_Number);
Some(MediaExpressionValue::Float(css_value.float_unchecked()))
}
},
nsMediaFeature_ValueType::eBoolInteger => {
debug_assert_eq!(css_value.mUnit, nsCSSUnit::eCSSUnit_Integer);
let i = css_value.integer_unchecked();
debug_assert!(i == 0 || i == 1);
Some(MediaExpressionValue::BoolInteger(i == 1))
}
},
nsMediaFeature_ValueType::eResolution => {
debug_assert_eq!(css_value.mUnit, nsCSSUnit::eCSSUnit_Pixel);
Some(MediaExpressionValue::Resolution(Resolution::Dppx(css_value.float_unchecked())))
}
Some(MediaExpressionValue::Resolution(Resolution::Dppx(
css_value.float_unchecked(),
)))
},
nsMediaFeature_ValueType::eEnumerated => {
let value = css_value.integer_unchecked() as i16;
Some(MediaExpressionValue::Enumerated(value))
}
},
nsMediaFeature_ValueType::eIdent => {
debug_assert_eq!(css_value.mUnit, nsCSSUnit::eCSSUnit_AtomIdent);
Some(MediaExpressionValue::Ident(unsafe {
Atom::from_raw(*css_value.mValue.mAtom.as_ref())
}))
}
},
nsMediaFeature_ValueType::eIntRatio => {
let array = unsafe { css_value.array_unchecked() };
debug_assert_eq!(array.len(), 2);
@ -407,31 +416,28 @@ impl MediaExpressionValue {
debug_assert!(first >= 0 && second >= 0);
Some(MediaExpressionValue::IntRatio(first as u32, second as u32))
}
},
}
}
}
impl MediaExpressionValue {
fn to_css<W>(&self, dest: &mut CssWriter<W>, for_expr: &Expression) -> fmt::Result
where W: fmt::Write,
where
W: fmt::Write,
{
match *self {
MediaExpressionValue::Length(ref l) => l.to_css(dest),
MediaExpressionValue::Integer(v) => v.to_css(dest),
MediaExpressionValue::Float(v) => v.to_css(dest),
MediaExpressionValue::BoolInteger(v) => {
dest.write_str(if v { "1" } else { "0" })
},
MediaExpressionValue::BoolInteger(v) => dest.write_str(if v { "1" } else { "0" }),
MediaExpressionValue::IntRatio(a, b) => {
a.to_css(dest)?;
dest.write_char('/')?;
b.to_css(dest)
},
MediaExpressionValue::Resolution(ref r) => r.to_css(dest),
MediaExpressionValue::Ident(ref ident) => {
serialize_atom_identifier(ident, dest)
}
MediaExpressionValue::Ident(ref ident) => serialize_atom_identifier(ident, dest),
MediaExpressionValue::Enumerated(value) => unsafe {
use std::{slice, str};
use std::os::raw::c_char;
@ -440,20 +446,18 @@ impl MediaExpressionValue {
// well-formed utf-8.
let mut length = 0;
let (keyword, _value) =
find_in_table(*for_expr.feature.mData.mKeywordTable.as_ref(),
|_kw, val| val == value)
.expect("Value not found in the keyword table?");
let (keyword, _value) = find_in_table(
*for_expr.feature.mData.mKeywordTable.as_ref(),
|_kw, val| val == value,
).expect("Value not found in the keyword table?");
let buffer: *const c_char =
bindings::Gecko_CSSKeywordString(keyword, &mut length);
let buffer =
slice::from_raw_parts(buffer as *const u8, length as usize);
let buffer: *const c_char = bindings::Gecko_CSSKeywordString(keyword, &mut length);
let buffer = slice::from_raw_parts(buffer as *const u8, length as usize);
let string = str::from_utf8_unchecked(buffer);
dest.write_str(string)
}
},
}
}
}
@ -479,7 +483,7 @@ unsafe fn find_in_table<F>(
mut f: F,
) -> Option<(nsCSSKeyword, i16)>
where
F: FnMut(nsCSSKeyword, i16) -> bool
F: FnMut(nsCSSKeyword, i16) -> bool,
{
loop {
let value = (*current_entry).mValue;
@ -511,52 +515,50 @@ fn parse_feature_value<'i, 't>(
nsMediaFeature_ValueType::eInteger => {
let integer = Integer::parse_non_negative(context, input)?;
MediaExpressionValue::Integer(integer.value() as u32)
}
},
nsMediaFeature_ValueType::eBoolInteger => {
let integer = Integer::parse_non_negative(context, input)?;
let value = integer.value();
if value > 1 {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError))
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
}
MediaExpressionValue::BoolInteger(value == 1)
}
},
nsMediaFeature_ValueType::eFloat => {
let number = Number::parse(context, input)?;
MediaExpressionValue::Float(number.get())
}
},
nsMediaFeature_ValueType::eIntRatio => {
let a = Integer::parse_positive(context, input)?;
input.expect_delim('/')?;
let b = Integer::parse_positive(context, input)?;
MediaExpressionValue::IntRatio(a.value() as u32, b.value() as u32)
}
},
nsMediaFeature_ValueType::eResolution => {
MediaExpressionValue::Resolution(Resolution::parse(input)?)
}
},
nsMediaFeature_ValueType::eEnumerated => {
let location = input.current_source_location();
let keyword = input.expect_ident()?;
let keyword = unsafe {
bindings::Gecko_LookupCSSKeyword(
keyword.as_bytes().as_ptr(),
keyword.len() as u32,
)
bindings::Gecko_LookupCSSKeyword(keyword.as_bytes().as_ptr(), keyword.len() as u32)
};
let first_table_entry: *const nsCSSProps_KTableEntry = unsafe {
*feature.mData.mKeywordTable.as_ref()
};
let first_table_entry: *const nsCSSProps_KTableEntry =
unsafe { *feature.mData.mKeywordTable.as_ref() };
let value = match unsafe { find_in_table(first_table_entry, |kw, _| kw == keyword) } {
Some((_kw, value)) => value,
None => return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError)),
None => {
return Err(location.new_custom_error(StyleParseErrorKind::UnspecifiedError))
},
};
MediaExpressionValue::Enumerated(value)
}
},
nsMediaFeature_ValueType::eIdent => {
MediaExpressionValue::Ident(Atom::from(input.expect_ident()?.as_ref()))
}
},
};
Ok(value)
@ -569,7 +571,11 @@ impl Expression {
value: Option<MediaExpressionValue>,
range: Range,
) -> Self {
Self { feature, value, range }
Self {
feature,
value,
range,
}
}
/// Parse a media expression of the form:
@ -581,12 +587,14 @@ impl Expression {
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
input.expect_parenthesis_block().map_err(|err|
input.expect_parenthesis_block().map_err(|err| {
err.location.new_custom_error(match err.kind {
BasicParseErrorKind::UnexpectedToken(t) => StyleParseErrorKind::ExpectedIdentifier(t),
BasicParseErrorKind::UnexpectedToken(t) => {
StyleParseErrorKind::ExpectedIdentifier(t)
},
_ => StyleParseErrorKind::UnspecifiedError,
})
)?;
})?;
input.parse_nested_block(|input| {
// FIXME: remove extra indented block when lifetimes are non-lexical
@ -594,17 +602,19 @@ impl Expression {
let range;
{
let location = input.current_source_location();
let ident = input.expect_ident().map_err(|err|
let ident = input.expect_ident().map_err(|err| {
err.location.new_custom_error(match err.kind {
BasicParseErrorKind::UnexpectedToken(t) => StyleParseErrorKind::ExpectedIdentifier(t),
BasicParseErrorKind::UnexpectedToken(t) => {
StyleParseErrorKind::ExpectedIdentifier(t)
},
_ => StyleParseErrorKind::UnspecifiedError,
})
)?;
})?;
let mut flags = 0;
if context.chrome_rules_enabled() ||
context.stylesheet_origin == Origin::UserAgent {
if context.chrome_rules_enabled() || context.stylesheet_origin == Origin::UserAgent
{
flags |= structs::nsMediaFeature_RequirementFlags_eUserAgentAndChromeOnly;
}
@ -612,10 +622,13 @@ impl Expression {
let mut feature_name = &**ident;
if unsafe { structs::StaticPrefs_sVarCache_layout_css_prefixes_webkit } &&
starts_with_ignore_ascii_case(feature_name, "-webkit-") {
starts_with_ignore_ascii_case(feature_name, "-webkit-")
{
feature_name = &feature_name[8..];
flags |= structs::nsMediaFeature_RequirementFlags_eHasWebkitPrefix;
if unsafe { structs::StaticPrefs_sVarCache_layout_css_prefixes_device_pixel_ratio_webkit } {
if unsafe {
structs::StaticPrefs_sVarCache_layout_css_prefixes_device_pixel_ratio_webkit
} {
flags |= structs::nsMediaFeature_RequirementFlags_eWebkitDevicePixelRatioPrefEnabled;
}
}
@ -641,25 +654,26 @@ impl Expression {
Ok((f, r)) => {
feature = f;
range = r;
}
},
Err(()) => {
return Err(location.new_custom_error(
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone())
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone()),
))
}
},
}
if (feature.mReqFlags & !flags) != 0 {
return Err(location.new_custom_error(
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone())
))
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone()),
));
}
if range != Range::Equal &&
feature.mRangeType != nsMediaFeature_RangeType::eMinMaxAllowed {
feature.mRangeType != nsMediaFeature_RangeType::eMinMaxAllowed
{
return Err(location.new_custom_error(
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone())
))
StyleParseErrorKind::MediaQueryExpectedFeatureName(ident.clone()),
));
}
}
@ -670,16 +684,16 @@ impl Expression {
// reject them here too.
if input.try(|i| i.expect_colon()).is_err() {
if range != Range::Equal {
return Err(input.new_custom_error(StyleParseErrorKind::RangedExpressionWithNoValue))
return Err(input.new_custom_error(StyleParseErrorKind::RangedExpressionWithNoValue));
}
return Ok(Expression::new(feature, None, range));
}
let value = parse_feature_value(feature,
feature.mValueType,
context, input).map_err(|err|
err.location.new_custom_error(StyleParseErrorKind::MediaQueryExpectedFeatureValue)
)?;
let value =
parse_feature_value(feature, feature.mValueType, context, input).map_err(|err| {
err.location
.new_custom_error(StyleParseErrorKind::MediaQueryExpectedFeatureValue)
})?;
Ok(Expression::new(feature, Some(value), range))
})
@ -690,7 +704,10 @@ impl Expression {
let mut css_value = nsCSSValue::null();
unsafe {
(self.feature.mGetter.unwrap())(
device.pres_context().mDocument.raw::<structs::nsIDocument>(),
device
.pres_context()
.mDocument
.raw::<structs::nsIDocument>(),
self.feature,
&mut css_value,
)
@ -713,9 +730,11 @@ impl Expression {
use self::MediaExpressionValue::*;
use std::cmp::Ordering;
debug_assert!(self.range == Range::Equal ||
self.feature.mRangeType == nsMediaFeature_RangeType::eMinMaxAllowed,
"Whoops, wrong range");
debug_assert!(
self.range == Range::Equal ||
self.feature.mRangeType == nsMediaFeature_RangeType::eMinMaxAllowed,
"Whoops, wrong range"
);
// http://dev.w3.org/csswg/mediaqueries3/#units
// em units are relative to the initial font-size.
@ -727,54 +746,57 @@ impl Expression {
return match *actual_value {
BoolInteger(v) => v,
Integer(v) => v != 0,
Length(ref l) => {
computed::Context::for_media_query_evaluation(
device,
quirks_mode,
|context| l.to_computed_value(&context).px() != 0.,
)
},
Length(ref l) => computed::Context::for_media_query_evaluation(
device,
quirks_mode,
|context| l.to_computed_value(&context).px() != 0.,
),
_ => true,
}
}
};
},
};
// FIXME(emilio): Handle the possible floating point errors?
let cmp = match (required_value, actual_value) {
(&Length(ref one), &Length(ref other)) => {
computed::Context::for_media_query_evaluation(device, quirks_mode, |context| {
one.to_computed_value(&context).to_i32_au()
one.to_computed_value(&context)
.to_i32_au()
.cmp(&other.to_computed_value(&context).to_i32_au())
})
}
},
(&Integer(one), &Integer(ref other)) => one.cmp(other),
(&BoolInteger(one), &BoolInteger(ref other)) => one.cmp(other),
(&Float(one), &Float(ref other)) => one.partial_cmp(other).unwrap(),
(&IntRatio(one_num, one_den), &IntRatio(other_num, other_den)) => {
// Extend to avoid overflow.
(one_num as u64 * other_den as u64).cmp(
&(other_num as u64 * one_den as u64))
}
(one_num as u64 * other_den as u64).cmp(&(other_num as u64 * one_den as u64))
},
(&Resolution(ref one), &Resolution(ref other)) => {
let actual_dpi = unsafe {
if (*device.pres_context).mOverrideDPPX > 0.0 {
self::Resolution::Dppx((*device.pres_context).mOverrideDPPX)
.to_dpi()
self::Resolution::Dppx((*device.pres_context).mOverrideDPPX).to_dpi()
} else {
other.to_dpi()
}
};
one.to_dpi().partial_cmp(&actual_dpi).unwrap()
}
},
(&Ident(ref one), &Ident(ref other)) => {
debug_assert_ne!(self.feature.mRangeType, nsMediaFeature_RangeType::eMinMaxAllowed);
debug_assert_ne!(
self.feature.mRangeType,
nsMediaFeature_RangeType::eMinMaxAllowed
);
return one == other;
}
},
(&Enumerated(one), &Enumerated(other)) => {
debug_assert_ne!(self.feature.mRangeType, nsMediaFeature_RangeType::eMinMaxAllowed);
debug_assert_ne!(
self.feature.mRangeType,
nsMediaFeature_RangeType::eMinMaxAllowed
);
return one == other;
}
},
_ => unreachable!(),
};