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

@ -9,7 +9,7 @@
use app_units::Au;
use context::QuirksMode;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser, parse_important};
use cssparser::{parse_important, AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use cssparser::CowRcStr;
use error_reporting::{ContextualParseError, ParseErrorReporter};
use euclid::TypedSize2D;
@ -28,15 +28,18 @@ use std::str::Chars;
use str::CssStringWriter;
use style_traits::{CssWriter, ParseError, PinchZoomFactor, StyleParseErrorKind, ToCss};
use style_traits::viewport::{Orientation, UserZoom, ViewportConstraints, Zoom};
use stylesheets::{StylesheetInDocument, Origin};
use stylesheets::{Origin, StylesheetInDocument};
use values::computed::{Context, ToComputedValue};
use values::specified::{NoCalcLength, LengthOrPercentageOrAuto, ViewportPercentageLength};
use values::specified::{LengthOrPercentageOrAuto, NoCalcLength, ViewportPercentageLength};
/// Whether parsing and processing of `@viewport` rules is enabled.
#[cfg(feature = "servo")]
pub fn enabled() -> bool {
use servo_config::prefs::PREFS;
PREFS.get("layout.viewport.enabled").as_boolean().unwrap_or(false)
PREFS
.get("layout.viewport.enabled")
.as_boolean()
.unwrap_or(false)
}
/// Whether parsing and processing of `@viewport` rules is enabled.
@ -147,7 +150,7 @@ trait FromMeta: Sized {
#[derive(Clone, Debug, PartialEq, ToCss)]
pub enum ViewportLength {
Specified(LengthOrPercentageOrAuto),
ExtendToZoom
ExtendToZoom,
}
impl FromMeta for ViewportLength {
@ -155,28 +158,30 @@ impl FromMeta for ViewportLength {
macro_rules! specified {
($value:expr) => {
ViewportLength::Specified(LengthOrPercentageOrAuto::Length($value))
}
};
}
Some(match value {
v if v.eq_ignore_ascii_case("device-width") =>
specified!(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.))),
v if v.eq_ignore_ascii_case("device-height") =>
specified!(NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(100.))),
_ => {
match value.parse::<f32>() {
Ok(n) if n >= 0. => specified!(NoCalcLength::from_px(n.max(1.).min(10000.))),
Ok(_) => return None,
Err(_) => specified!(NoCalcLength::from_px(1.))
}
}
v if v.eq_ignore_ascii_case("device-width") => specified!(
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vw(100.))
),
v if v.eq_ignore_ascii_case("device-height") => specified!(
NoCalcLength::ViewportPercentage(ViewportPercentageLength::Vh(100.))
),
_ => match value.parse::<f32>() {
Ok(n) if n >= 0. => specified!(NoCalcLength::from_px(n.max(1.).min(10000.))),
Ok(_) => return None,
Err(_) => specified!(NoCalcLength::from_px(1.)),
},
})
}
}
impl ViewportLength {
fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>> {
fn parse<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
// we explicitly do not accept 'extend-to-zoom', since it is a UA
// internal value for <META> viewport translation
LengthOrPercentageOrAuto::parse_non_negative(context, input).map(ViewportLength::Specified)
@ -190,13 +195,11 @@ impl FromMeta for Zoom {
v if v.eq_ignore_ascii_case("no") => Zoom::Number(0.1),
v if v.eq_ignore_ascii_case("device-width") => Zoom::Number(10.),
v if v.eq_ignore_ascii_case("device-height") => Zoom::Number(10.),
_ => {
match value.parse::<f32>() {
Ok(n) if n >= 0. => Zoom::Number(n.max(0.1).min(10.)),
Ok(_) => return None,
Err(_) => Zoom::Number(0.1),
}
}
_ => match value.parse::<f32>() {
Ok(n) if n >= 0. => Zoom::Number(n.max(0.1).min(10.)),
Ok(_) => return None,
Err(_) => Zoom::Number(0.1),
},
})
}
}
@ -208,18 +211,16 @@ impl FromMeta for UserZoom {
v if v.eq_ignore_ascii_case("no") => UserZoom::Fixed,
v if v.eq_ignore_ascii_case("device-width") => UserZoom::Zoom,
v if v.eq_ignore_ascii_case("device-height") => UserZoom::Zoom,
_ => {
match value.parse::<f32>() {
Ok(n) if n >= 1. || n <= -1. => UserZoom::Zoom,
_ => UserZoom::Fixed
}
}
_ => match value.parse::<f32>() {
Ok(n) if n >= 1. || n <= -1. => UserZoom::Zoom,
_ => UserZoom::Fixed,
},
})
}
}
struct ViewportRuleParser<'a, 'b: 'a> {
context: &'a ParserContext<'b>
context: &'a ParserContext<'b>,
}
#[derive(Clone, Debug, PartialEq)]
@ -228,19 +229,20 @@ struct ViewportRuleParser<'a, 'b: 'a> {
pub struct ViewportDescriptorDeclaration {
pub origin: Origin,
pub descriptor: ViewportDescriptor,
pub important: bool
pub important: bool,
}
impl ViewportDescriptorDeclaration {
#[allow(missing_docs)]
pub fn new(origin: Origin,
descriptor: ViewportDescriptor,
important: bool) -> ViewportDescriptorDeclaration
{
pub fn new(
origin: Origin,
descriptor: ViewportDescriptor,
important: bool,
) -> ViewportDescriptorDeclaration {
ViewportDescriptorDeclaration {
origin: origin,
descriptor: descriptor,
important: important
important: important,
}
}
}
@ -258,12 +260,14 @@ impl ToCss for ViewportDescriptorDeclaration {
}
}
fn parse_shorthand<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
-> Result<(ViewportLength, ViewportLength), ParseError<'i>> {
fn parse_shorthand<'i, 't>(
context: &ParserContext,
input: &mut Parser<'i, 't>,
) -> Result<(ViewportLength, ViewportLength), ParseError<'i>> {
let min = ViewportLength::parse(context, input)?;
match input.try(|i| ViewportLength::parse(context, i)) {
Err(_) => Ok((min.clone(), min)),
Ok(max) => Ok((min, max))
Ok(max) => Ok((min, max)),
}
}
@ -278,8 +282,11 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
type Declaration = Vec<ViewportDescriptorDeclaration>;
type Error = StyleParseErrorKind<'i>;
fn parse_value<'t>(&mut self, name: CowRcStr<'i>, input: &mut Parser<'i, 't>)
-> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> {
fn parse_value<'t>(
&mut self,
name: CowRcStr<'i>,
input: &mut Parser<'i, 't>,
) -> Result<Vec<ViewportDescriptorDeclaration>, ParseError<'i>> {
macro_rules! declaration {
($declaration:ident($parse:expr)) => {
declaration!($declaration(value: try!($parse(input)),
@ -301,9 +308,11 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
let shorthand = parse_shorthand(self.context, input)?;
let important = input.try(parse_important).is_ok();
Ok(vec![declaration!($min(value: shorthand.0, important: important)),
declaration!($max(value: shorthand.1, important: important))])
}}
Ok(vec![
declaration!($min(value: shorthand.0, important: important)),
declaration!($max(value: shorthand.1, important: important)),
])
}};
}
match_ignore_ascii_case! { &*name,
@ -328,7 +337,7 @@ impl<'a, 'b, 'i> DeclarationParser<'i> for ViewportRuleParser<'a, 'b> {
#[cfg_attr(feature = "servo", derive(MallocSizeOf))]
pub struct ViewportRule {
/// The declarations contained in this @viewport rule.
pub declarations: Vec<ViewportDescriptorDeclaration>
pub declarations: Vec<ViewportDescriptorDeclaration>,
}
/// Whitespace as defined by DEVICE-ADAPT § 9.2
@ -346,11 +355,13 @@ fn is_whitespace_separator_or_equals(c: &char) -> bool {
impl ViewportRule {
/// Parse a single @viewport rule.
pub fn parse<'i, 't, R>(context: &ParserContext,
error_context: &ParserErrorContext<R>,
input: &mut Parser<'i, 't>)
-> Result<Self, ParseError<'i>>
where R: ParseErrorReporter
pub fn parse<'i, 't, R>(
context: &ParserContext,
error_context: &ParserErrorContext<R>,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>>
where
R: ParseErrorReporter,
{
let parser = ViewportRuleParser { context: context };
@ -362,15 +373,20 @@ impl ViewportRule {
for declarations in declarations {
cascade.add(Cow::Owned(declarations))
}
}
},
Err((error, slice)) => {
let location = error.location;
let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(slice, error);
let error = ContextualParseError::UnsupportedViewportDescriptorDeclaration(
slice,
error,
);
context.log_css_error(error_context, location, error);
}
},
}
}
Ok(ViewportRule { declarations: cascade.finish() })
Ok(ViewportRule {
declarations: cascade.finish(),
})
}
}
@ -385,9 +401,10 @@ impl ViewportRule {
declarations[discriminant] = Some(ViewportDescriptorDeclaration::new(
Origin::Author,
descriptor,
false));
}
}}
false,
));
}};
}
let mut has_width = false;
let mut has_height = false;
@ -397,16 +414,15 @@ impl ViewportRule {
macro_rules! start_of_name {
($iter:ident) => {
$iter.by_ref()
$iter
.by_ref()
.skip_while(|&(_, c)| is_whitespace_separator_or_equals(&c))
.next()
}
};
}
while let Some((start, _)) = start_of_name!(iter) {
let property = ViewportRule::parse_meta_property(content,
&mut iter,
start);
let property = ViewportRule::parse_meta_property(content, &mut iter, start);
if let Some((name, value)) = property {
macro_rules! push {
@ -414,7 +430,7 @@ impl ViewportRule {
if let Some(value) = $translate(value) {
push_descriptor!($descriptor(value));
}
}
};
}
match name {
@ -424,27 +440,26 @@ impl ViewportRule {
push_descriptor!(MaxWidth(value));
has_width = true;
}
}
},
n if n.eq_ignore_ascii_case("height") => {
if let Some(value) = ViewportLength::from_meta(value) {
push_descriptor!(MinHeight(ViewportLength::ExtendToZoom));
push_descriptor!(MaxHeight(value));
has_height = true;
}
}
},
n if n.eq_ignore_ascii_case("initial-scale") => {
if let Some(value) = Zoom::from_meta(value) {
push_descriptor!(Zoom(value));
has_zoom = true;
}
}
n if n.eq_ignore_ascii_case("minimum-scale") =>
push!(MinZoom(Zoom::from_meta)),
n if n.eq_ignore_ascii_case("maximum-scale") =>
push!(MaxZoom(Zoom::from_meta)),
n if n.eq_ignore_ascii_case("user-scalable") =>
push!(UserZoom(UserZoom::from_meta)),
_ => {}
},
n if n.eq_ignore_ascii_case("minimum-scale") => push!(MinZoom(Zoom::from_meta)),
n if n.eq_ignore_ascii_case("maximum-scale") => push!(MaxZoom(Zoom::from_meta)),
n if n.eq_ignore_ascii_case("user-scalable") => {
push!(UserZoom(UserZoom::from_meta))
},
_ => {},
}
}
}
@ -453,8 +468,12 @@ impl ViewportRule {
// http://dev.w3.org/csswg/css-device-adapt/#width-and-height-properties
if !has_width && has_zoom {
if has_height {
push_descriptor!(MinWidth(ViewportLength::Specified(LengthOrPercentageOrAuto::Auto)));
push_descriptor!(MaxWidth(ViewportLength::Specified(LengthOrPercentageOrAuto::Auto)));
push_descriptor!(MinWidth(ViewportLength::Specified(
LengthOrPercentageOrAuto::Auto
)));
push_descriptor!(MaxWidth(ViewportLength::Specified(
LengthOrPercentageOrAuto::Auto
)));
} else {
push_descriptor!(MinWidth(ViewportLength::ExtendToZoom));
push_descriptor!(MaxWidth(ViewportLength::ExtendToZoom));
@ -463,17 +482,19 @@ impl ViewportRule {
let declarations: Vec<_> = declarations.into_iter().filter_map(|entry| entry).collect();
if !declarations.is_empty() {
Some(ViewportRule { declarations: declarations })
Some(ViewportRule {
declarations: declarations,
})
} else {
None
}
}
fn parse_meta_property<'a>(content: &'a str,
iter: &mut Enumerate<Chars<'a>>,
start: usize)
-> Option<(&'a str, &'a str)>
{
fn parse_meta_property<'a>(
content: &'a str,
iter: &mut Enumerate<Chars<'a>>,
start: usize,
) -> Option<(&'a str, &'a str)> {
fn end_of_token(iter: &mut Enumerate<Chars>) -> Option<(usize, char)> {
iter.by_ref()
.skip_while(|&(_, c)| !is_whitespace_separator_or_equals(&c))
@ -488,25 +509,23 @@ impl ViewportRule {
// <name> <whitespace>* '='
let end = match end_of_token(iter) {
Some((end, c)) if WHITESPACE.contains(&c) => {
match skip_whitespace(iter) {
Some((_, c)) if c == '=' => end,
_ => return None
}
}
Some((end, c)) if WHITESPACE.contains(&c) => match skip_whitespace(iter) {
Some((_, c)) if c == '=' => end,
_ => return None,
},
Some((end, c)) if c == '=' => end,
_ => return None
_ => return None,
};
let name = &content[start..end];
// <whitespace>* <value>
let start = match skip_whitespace(iter) {
Some((start, c)) if !SEPARATOR.contains(&c) => start,
_ => return None
_ => return None,
};
let value = match end_of_token(iter) {
Some((end, _)) => &content[start..end],
_ => &content[start..]
_ => &content[start..],
};
Some((name, value))
@ -567,7 +586,7 @@ impl Cascade {
pub fn from_stylesheets<'a, I, S>(
stylesheets: I,
guards: &StylesheetGuards,
device: &Device
device: &Device,
) -> Self
where
I: Iterator<Item = (&'a S, Origin)>,
@ -584,7 +603,7 @@ impl Cascade {
cascade
}
pub fn add(&mut self, declaration: Cow<ViewportDescriptorDeclaration>) {
pub fn add(&mut self, declaration: Cow<ViewportDescriptorDeclaration>) {
let descriptor = declaration.descriptor.discriminant_value();
match self.declarations[descriptor] {
@ -593,18 +612,22 @@ impl Cascade {
*entry_declaration = declaration.into_owned();
*order_of_appearance = self.count_so_far;
}
}
},
ref mut entry @ None => {
*entry = Some((self.count_so_far, declaration.into_owned()));
}
},
}
self.count_so_far += 1;
}
pub fn finish(mut self) -> Vec<ViewportDescriptorDeclaration> {
// sort the descriptors by order of appearance
self.declarations.sort_by_key(|entry| entry.as_ref().map(|&(index, _)| index));
self.declarations.into_iter().filter_map(|entry| entry.map(|(_, decl)| decl)).collect()
self.declarations
.sort_by_key(|entry| entry.as_ref().map(|&(index, _)| index));
self.declarations
.into_iter()
.filter_map(|entry| entry.map(|(_, decl)| decl))
.collect()
}
}
@ -612,22 +635,23 @@ impl Cascade {
pub trait MaybeNew {
/// Create a ViewportConstraints from a viewport size and a `@viewport`
/// rule.
fn maybe_new(device: &Device,
rule: &ViewportRule,
quirks_mode: QuirksMode)
-> Option<ViewportConstraints>;
fn maybe_new(
device: &Device,
rule: &ViewportRule,
quirks_mode: QuirksMode,
) -> Option<ViewportConstraints>;
}
impl MaybeNew for ViewportConstraints {
fn maybe_new(device: &Device,
rule: &ViewportRule,
quirks_mode: QuirksMode)
-> Option<ViewportConstraints>
{
fn maybe_new(
device: &Device,
rule: &ViewportRule,
quirks_mode: QuirksMode,
) -> Option<ViewportConstraints> {
use std::cmp;
if rule.declarations.is_empty() {
return None
return None;
}
let mut min_width = None;
@ -657,7 +681,7 @@ impl MaybeNew for ViewportConstraints {
ViewportDescriptor::MaxZoom(value) => max_zoom = value.to_f32(),
ViewportDescriptor::UserZoom(value) => user_zoom = value,
ViewportDescriptor::Orientation(value) => orientation = value
ViewportDescriptor::Orientation(value) => orientation = value,
}
}
@ -671,17 +695,17 @@ impl MaybeNew for ViewportConstraints {
(None, b) => b,
(Some(a), Some(b)) => Some(a.$op(b)),
}
}
};
}
macro_rules! min {
($opta:expr, $optb:expr) => {
choose!(min, $opta, $optb)
}
};
}
macro_rules! max {
($opta:expr, $optb:expr) => {
choose!(max, $opta, $optb)
}
};
}
// DEVICE-ADAPT § 6.2.1 Resolve min-zoom and max-zoom values
@ -731,14 +755,16 @@ impl MaybeNew for ViewportConstraints {
if let Some($value) = $value {
match *$value {
ViewportLength::Specified(ref length) => match *length {
LengthOrPercentageOrAuto::Length(ref value) =>
Some(Au::from(value.to_computed_value(&context))),
LengthOrPercentageOrAuto::Percentage(value) =>
Some(initial_viewport.$dimension.scale_by(value.0)),
LengthOrPercentageOrAuto::Length(ref value) => {
Some(Au::from(value.to_computed_value(&context)))
},
LengthOrPercentageOrAuto::Percentage(value) => {
Some(initial_viewport.$dimension.scale_by(value.0))
},
LengthOrPercentageOrAuto::Auto => None,
LengthOrPercentageOrAuto::Calc(ref calc) => {
calc.to_computed_value(&context).to_used_value(Some(initial_viewport.$dimension))
}
LengthOrPercentageOrAuto::Calc(ref calc) => calc.to_computed_value(
&context,
).to_used_value(Some(initial_viewport.$dimension)),
},
ViewportLength::ExtendToZoom => {
// $extend_to will be 'None' if 'extend-to-zoom' is 'auto'
@ -746,14 +772,14 @@ impl MaybeNew for ViewportConstraints {
(None, None) => None,
(a, None) => a,
(None, b) => b,
(a, b) => cmp::max(a, b)
(a, b) => cmp::max(a, b),
}
}
},
}
} else {
None
}
}
};
}
// DEVICE-ADAPT § 9.3 states that max-descriptors need to be resolved
@ -771,17 +797,17 @@ impl MaybeNew for ViewportConstraints {
if $min.is_some() || $max.is_some() {
let max = match $max {
Some(max) => cmp::min(max, $initial),
None => $initial
None => $initial,
};
Some(match $min {
Some(min) => cmp::max(min, max),
None => max
None => max,
})
} else {
None
};
}
};
}
let width = resolve!(min_width, max_width, initial_viewport.width);
@ -789,7 +815,7 @@ impl MaybeNew for ViewportConstraints {
// DEVICE-ADAPT § 6.2.5 Resolve width value
let width = if width.is_none() && height.is_none() {
Some(initial_viewport.width)
Some(initial_viewport.width)
} else {
width
};
@ -799,7 +825,7 @@ impl MaybeNew for ViewportConstraints {
initial_height => {
let ratio = initial_viewport.width.to_f32_px() / initial_height.to_f32_px();
Au::from_f32_px(height.unwrap().to_f32_px() * ratio)
}
},
});
// DEVICE-ADAPT § 6.2.6 Resolve height value
@ -808,7 +834,7 @@ impl MaybeNew for ViewportConstraints {
initial_width => {
let ratio = initial_viewport.height.to_f32_px() / initial_width.to_f32_px();
Au::from_f32_px(width.to_f32_px() * ratio)
}
},
});
Some(ViewportConstraints {
@ -820,7 +846,7 @@ impl MaybeNew for ViewportConstraints {
max_zoom: max_zoom.map(PinchZoomFactor::new),
user_zoom: user_zoom,
orientation: orientation
orientation: orientation,
})
}
}