Skip to content

Commit

Permalink
Format style component.
Browse files Browse the repository at this point in the history
  • Loading branch information
chansuke authored and emilio committed Sep 9, 2018
1 parent 31fc6cd commit 8dab4d6
Show file tree
Hide file tree
Showing 120 changed files with 2,207 additions and 1,417 deletions.
26 changes: 14 additions & 12 deletions components/style/animation.rs
Expand Up @@ -213,7 +213,12 @@ pub enum Animation {
/// node-dependent state (i.e. iteration count, etc.).
///
/// TODO(emilio): The animation object could be refcounted.
Keyframes(OpaqueNode, KeyframesAnimation, Atom, KeyframesAnimationState),
Keyframes(
OpaqueNode,
KeyframesAnimation,
Atom,
KeyframesAnimationState,
),
}

impl Animation {
Expand Down Expand Up @@ -304,8 +309,7 @@ impl PropertyAnimation {
let duration = box_style.transition_duration_mod(transition_index);

match transition_property {
TransitionProperty::Custom(..) |
TransitionProperty::Unsupported(..) => result,
TransitionProperty::Custom(..) | TransitionProperty::Unsupported(..) => result,
TransitionProperty::Shorthand(ref shorthand_id) => shorthand_id
.longhands()
.filter_map(|longhand| {
Expand All @@ -316,8 +320,7 @@ impl PropertyAnimation {
old_style,
new_style,
)
})
.collect(),
}).collect(),
TransitionProperty::Longhand(longhand_id) => {
let animation = PropertyAnimation::from_longhand(
longhand_id,
Expand Down Expand Up @@ -455,8 +458,7 @@ pub fn start_transitions_if_applicable(
property_animation: property_animation,
},
/* is_expired = */ false,
))
.unwrap();
)).unwrap();

had_animations = true;
}
Expand Down Expand Up @@ -505,7 +507,9 @@ where
Some(previous_style),
Some(previous_style),
font_metrics_provider,
CascadeMode::Unvisited { visited_rules: None },
CascadeMode::Unvisited {
visited_rules: None,
},
context.quirks_mode(),
/* rule_cache = */ None,
&mut Default::default(),
Expand Down Expand Up @@ -596,8 +600,7 @@ where
expired: false,
cascade_style: new_style.clone(),
},
))
.unwrap();
)).unwrap();
had_animations = true;
}
}
Expand Down Expand Up @@ -735,8 +738,7 @@ pub fn update_style_for_animation<E>(
} else {
None
}
})
.unwrap_or(animation.steps.len() - 1);
}).unwrap_or(animation.steps.len() - 1);
},
_ => unreachable!(),
}
Expand Down
6 changes: 4 additions & 2 deletions components/style/applicable_declarations.rs
Expand Up @@ -38,7 +38,8 @@ const SOURCE_ORDER_MASK: u32 = SOURCE_ORDER_MAX << SOURCE_ORDER_SHIFT;
const SHADOW_CASCADE_ORDER_SHIFT: usize = SOURCE_ORDER_BITS;
const SHADOW_CASCADE_ORDER_BITS: usize = 4;
const SHADOW_CASCADE_ORDER_MAX: u8 = (1 << SHADOW_CASCADE_ORDER_BITS) - 1;
const SHADOW_CASCADE_ORDER_MASK: u32 = (SHADOW_CASCADE_ORDER_MAX as u32) << SHADOW_CASCADE_ORDER_SHIFT;
const SHADOW_CASCADE_ORDER_MASK: u32 =
(SHADOW_CASCADE_ORDER_MAX as u32) << SHADOW_CASCADE_ORDER_SHIFT;

const CASCADE_LEVEL_SHIFT: usize = SOURCE_ORDER_BITS + SHADOW_CASCADE_ORDER_BITS;
const CASCADE_LEVEL_BITS: usize = 4;
Expand All @@ -61,7 +62,8 @@ impl ApplicableDeclarationBits {
"Gotta find more bits!"
);
let mut bits = ::std::cmp::min(source_order, SOURCE_ORDER_MAX);
bits |= ((shadow_cascade_order & SHADOW_CASCADE_ORDER_MAX) as u32) << SHADOW_CASCADE_ORDER_SHIFT;
bits |= ((shadow_cascade_order & SHADOW_CASCADE_ORDER_MAX) as u32) <<
SHADOW_CASCADE_ORDER_SHIFT;
bits |= (cascade_level as u8 as u32) << CASCADE_LEVEL_SHIFT;
ApplicableDeclarationBits(bits)
}
Expand Down
18 changes: 9 additions & 9 deletions components/style/attr.rs
Expand Up @@ -158,15 +158,15 @@ pub fn parse_double(string: &str) -> Result<f64, ()> {

impl AttrValue {
pub fn from_serialized_tokenlist(tokens: String) -> AttrValue {
let atoms = split_html_space_chars(&tokens).map(Atom::from).fold(
vec![],
|mut acc, atom| {
if !acc.contains(&atom) {
acc.push(atom)
}
acc
},
);
let atoms =
split_html_space_chars(&tokens)
.map(Atom::from)
.fold(vec![], |mut acc, atom| {
if !acc.contains(&atom) {
acc.push(atom)
}
acc
});
AttrValue::TokenList(tokens, atoms)
}

Expand Down
6 changes: 4 additions & 2 deletions components/style/author_styles.rs
Expand Up @@ -60,15 +60,17 @@ where
E: TElement,
S: ToMediaListKey,
{
let flusher = self.stylesheets
let flusher = self
.stylesheets
.flush::<E>(/* host = */ None, /* snapshot_map = */ None);

if flusher.sheets.dirty() {
self.quirks_mode = quirks_mode;
}

// Ignore OOM.
let _ = self.data
let _ = self
.data
.rebuild(device, quirks_mode, flusher.sheets, guard);
}
}
Expand Down
12 changes: 4 additions & 8 deletions components/style/build_gecko.rs
Expand Up @@ -322,13 +322,11 @@ mod bindings {
.expect(&format!(
"Unrecognized line in ServoArcTypeList.h: '{}'",
line
))
.get(1)
)).get(1)
.unwrap()
.as_str()
.to_string()
})
.collect()
}).collect()
}

struct BuilderWithConfig<'a> {
Expand Down Expand Up @@ -436,8 +434,7 @@ mod bindings {
servo,
if generic { "<T>" } else { "" }
))
})
.get_builder();
}).get_builder();
write_binding_file(builder, STRUCTS_FILE, &fixups);
}

Expand Down Expand Up @@ -553,8 +550,7 @@ mod bindings {
.raw_line(format!(
"pub type {0}Strong = ::gecko_bindings::sugar::ownership::Strong<{0}>;",
ty
))
.borrowed_type(ty)
)).borrowed_type(ty)
.zero_size_type(ty, &structs_types);
}
write_binding_file(builder, BINDINGS_FILE, &fixups);
Expand Down
13 changes: 7 additions & 6 deletions components/style/counter_style/mod.rs
Expand Up @@ -91,8 +91,7 @@ pub fn parse_counter_style_body<'i, 't>(
if let Err((error, slice)) = declaration {
let location = error.location;
let error = ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(
slice,
error,
slice, error,
);
context.log_css_error(location, error)
}
Expand All @@ -103,7 +102,8 @@ pub fn parse_counter_style_body<'i, 't>(
ref system @ System::Fixed { .. } |
ref system @ System::Symbolic |
ref system @ System::Alphabetic |
ref system @ System::Numeric if rule.symbols.is_none() =>
ref system @ System::Numeric
if rule.symbols.is_none() =>
{
let system = system.to_css_string();
Some(ContextualParseError::InvalidCounterStyleWithoutSymbols(
Expand Down Expand Up @@ -496,12 +496,13 @@ impl Parse for Ranges {
(opt_start, opt_end)
{
if start > end {
return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
return Err(
input.new_custom_error(StyleParseErrorKind::UnspecifiedError)
);
}
}
Ok(opt_start..opt_end)
})
.map(Ranges)
}).map(Ranges)
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions components/style/custom_properties.rs
Expand Up @@ -243,7 +243,8 @@ impl VariableValue {
self.first_token_type.set_if_nothing(css_first_token_type);
// If self.first_token_type was nothing,
// self.last_token_type is also nothing and this will be false:
if self.last_token_type
if self
.last_token_type
.needs_separator_when_before(css_first_token_type)
{
self.css.push_str("/**/")
Expand Down Expand Up @@ -569,7 +570,8 @@ impl<'a> CustomPropertiesBuilder<'a> {
_ => {},
}

let existing_value = self.custom_properties
let existing_value = self
.custom_properties
.as_ref()
.and_then(|m| m.get(name))
.or_else(|| self.inherited.and_then(|m| m.get(name)));
Expand Down
14 changes: 6 additions & 8 deletions components/style/data.rs
Expand Up @@ -272,12 +272,8 @@ impl ElementData {
return InvalidationResult::empty();
}

let mut processor = StateAndAttrInvalidationProcessor::new(
shared_context,
element,
self,
nth_index_cache,
);
let mut processor =
StateAndAttrInvalidationProcessor::new(shared_context, element, self, nth_index_cache);

let invalidator = TreeStyleInvalidator::new(element, stack_limit_checker, &mut processor);

Expand Down Expand Up @@ -305,7 +301,8 @@ impl ElementData {

/// Returns this element's primary style as a resolved style to use for sharing.
pub fn share_primary_style(&self) -> PrimaryStyle {
let reused_via_rule_node = self.flags
let reused_via_rule_node = self
.flags
.contains(ElementDataFlags::PRIMARY_STYLE_REUSED_VIA_RULE_NODE);

PrimaryStyle {
Expand Down Expand Up @@ -390,7 +387,8 @@ impl ElementData {
guards: &StylesheetGuards,
) -> bool {
debug_assert!(self.has_styles());
let (important_rules, _custom) = self.styles
let (important_rules, _custom) = self
.styles
.primary()
.rules()
.get_properties_overriding_animations(&guards);
Expand Down
15 changes: 8 additions & 7 deletions components/style/dom.rs
Expand Up @@ -42,7 +42,10 @@ use traversal_flags::TraversalFlags;
/// data structures. Also, layout code tends to be faster when the DOM is not being accessed, for
/// locality reasons. Using `OpaqueNode` enforces this invariant.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
#[cfg_attr(feature = "servo", derive(MallocSizeOf, Deserialize, Serialize))]
#[cfg_attr(
feature = "servo",
derive(MallocSizeOf, Deserialize, Serialize)
)]
pub struct OpaqueNode(pub usize);

impl OpaqueNode {
Expand Down Expand Up @@ -459,7 +462,9 @@ pub trait TElement:
fn is_svg_element(&self) -> bool;

/// Return whether this element is an element in the XUL namespace.
fn is_xul_element(&self) -> bool { false }
fn is_xul_element(&self) -> bool {
false
}

/// Return the list of slotted nodes of this node.
fn slotted_nodes(&self) -> &[Self::ConcreteNode] {
Expand Down Expand Up @@ -892,11 +897,7 @@ pub trait TElement:
/// of the `xml:lang=""` or `lang=""` attribute to use in place of
/// looking at the element and its ancestors. (This argument is used
/// to implement matching of `:lang()` against snapshots.)
fn match_element_lang(
&self,
override_lang: Option<Option<AttrValue>>,
value: &Lang,
) -> bool;
fn match_element_lang(&self, override_lang: Option<Option<AttrValue>>, value: &Lang) -> bool;

/// Returns whether this element is the main body element of the HTML
/// document it is on.
Expand Down
3 changes: 1 addition & 2 deletions components/style/dom_apis.rs
Expand Up @@ -426,8 +426,7 @@ where
return Ok(());
}

let elements =
fast_connected_elements_with_id(root, id, quirks_mode)?;
let elements = fast_connected_elements_with_id(root, id, quirks_mode)?;
if elements.is_empty() {
return Ok(());
}
Expand Down
30 changes: 15 additions & 15 deletions components/style/font_face.rs
Expand Up @@ -104,8 +104,9 @@ impl Parse for FontWeight {
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let first = AbsoluteFontWeight::parse(context, input)?;
let second =
input.try(|input| AbsoluteFontWeight::parse(context, input)).ok();
let second = input
.try(|input| AbsoluteFontWeight::parse(context, input))
.ok();
Ok(FontWeight(first, second))
}
}
Expand All @@ -122,8 +123,9 @@ impl Parse for FontStretch {
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>> {
let first = SpecifiedFontStretch::parse(context, input)?;
let second =
input.try(|input| SpecifiedFontStretch::parse(context, input)).ok();
let second = input
.try(|input| SpecifiedFontStretch::parse(context, input))
.ok();
Ok(FontStretch(first, second))
}
}
Expand All @@ -149,12 +151,12 @@ impl Parse for FontStyle {
GenericFontStyle::Normal => FontStyle::Normal,
GenericFontStyle::Italic => FontStyle::Italic,
GenericFontStyle::Oblique(angle) => {
let second_angle = input.try(|input| {
SpecifiedFontStyle::parse_angle(context, input)
}).unwrap_or_else(|_| angle.clone());
let second_angle = input
.try(|input| SpecifiedFontStyle::parse_angle(context, input))
.unwrap_or_else(|_| angle.clone());

FontStyle::Oblique(angle, second_angle)
}
},
})
}
}
Expand All @@ -178,7 +180,7 @@ impl ToCss for FontStyle {
second.to_css(dest)?;
}
Ok(())
}
},
}
}
}
Expand Down Expand Up @@ -235,15 +237,13 @@ impl<'a> FontFace<'a> {
// We support only opentype fonts and truetype is an alias for
// that format. Sources without format hints need to be
// downloaded in case we support them.
hints.is_empty() ||
hints.iter().any(|hint| {
hint == "truetype" || hint == "opentype" || hint == "woff"
})
hints.is_empty() || hints
.iter()
.any(|hint| hint == "truetype" || hint == "opentype" || hint == "woff")
} else {
true
}
})
.cloned()
}).cloned()
.collect(),
)
}
Expand Down

0 comments on commit 8dab4d6

Please sign in to comment.