style: Use consistent indentation in the stylist code.

This commit is contained in:
Emilio Cobos Álvarez 2017-08-25 13:34:36 +02:00
parent 772a8464eb
commit 5cd10b9eb7
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -671,13 +671,14 @@ impl Stylist {
/// parent; otherwise, non-inherited properties are reset to their initial /// parent; otherwise, non-inherited properties are reset to their initial
/// values. The flow constructor uses this flag when constructing anonymous /// values. The flow constructor uses this flag when constructing anonymous
/// flows. /// flows.
pub fn precomputed_values_for_pseudo(&self, pub fn precomputed_values_for_pseudo(
guards: &StylesheetGuards, &self,
pseudo: &PseudoElement, guards: &StylesheetGuards,
parent: Option<&ComputedValues>, pseudo: &PseudoElement,
cascade_flags: CascadeFlags, parent: Option<&ComputedValues>,
font_metrics: &FontMetricsProvider) cascade_flags: CascadeFlags,
-> Arc<ComputedValues> { font_metrics: &FontMetricsProvider
) -> Arc<ComputedValues> {
debug_assert!(pseudo.is_precomputed()); debug_assert!(pseudo.is_precomputed());
let rule_node = let rule_node =
@ -705,18 +706,20 @@ impl Stylist {
// descendant of a display: contents element where display: contents is // descendant of a display: contents element where display: contents is
// the actual used value, and the computed value of it would need // the actual used value, and the computed value of it would need
// blockification. // blockification.
properties::cascade(&self.device, properties::cascade(
Some(pseudo), &self.device,
&rule_node, Some(pseudo),
guards, &rule_node,
parent, guards,
parent, parent,
parent, parent,
None, parent,
None, None,
font_metrics, None,
cascade_flags, font_metrics,
self.quirks_mode) cascade_flags,
self.quirks_mode,
)
} }
/// Returns the style for an anonymous box of the given type. /// Returns the style for an anonymous box of the given type.
@ -769,38 +772,42 @@ impl Stylist {
/// ///
/// Check the documentation on lazy pseudo-elements in /// Check the documentation on lazy pseudo-elements in
/// docs/components/style.md /// docs/components/style.md
pub fn lazily_compute_pseudo_element_style<E>(&self, pub fn lazily_compute_pseudo_element_style<E>(
guards: &StylesheetGuards, &self,
element: &E, guards: &StylesheetGuards,
pseudo: &PseudoElement, element: &E,
rule_inclusion: RuleInclusion, pseudo: &PseudoElement,
parent_style: &ComputedValues, rule_inclusion: RuleInclusion,
is_probe: bool, parent_style: &ComputedValues,
font_metrics: &FontMetricsProvider) is_probe: bool,
-> Option<Arc<ComputedValues>> font_metrics: &FontMetricsProvider
where E: TElement, ) -> Option<Arc<ComputedValues>>
where
E: TElement,
{ {
let cascade_inputs = let cascade_inputs =
self.lazy_pseudo_rules(guards, element, pseudo, is_probe, rule_inclusion); self.lazy_pseudo_rules(guards, element, pseudo, is_probe, rule_inclusion);
self.compute_pseudo_element_style_with_inputs(&cascade_inputs, self.compute_pseudo_element_style_with_inputs(
pseudo, &cascade_inputs,
guards, pseudo,
parent_style, guards,
font_metrics) parent_style,
font_metrics,
)
} }
/// Computes a pseudo-element style lazily using the given CascadeInputs. /// Computes a pseudo-element style lazily using the given CascadeInputs.
/// This can be used for truly lazy pseudo-elements or to avoid redoing /// This can be used for truly lazy pseudo-elements or to avoid redoing
/// selector matching for eager pseudo-elements when we need to recompute /// selector matching for eager pseudo-elements when we need to recompute
/// their style with a new parent style. /// their style with a new parent style.
pub fn compute_pseudo_element_style_with_inputs(&self, pub fn compute_pseudo_element_style_with_inputs(
inputs: &CascadeInputs, &self,
pseudo: &PseudoElement, inputs: &CascadeInputs,
guards: &StylesheetGuards, pseudo: &PseudoElement,
parent_style: &ComputedValues, guards: &StylesheetGuards,
font_metrics: &FontMetricsProvider) parent_style: &ComputedValues,
-> Option<Arc<ComputedValues>> font_metrics: &FontMetricsProvider
{ ) -> Option<Arc<ComputedValues>> {
// We may have only visited rules in cases when we are actually // We may have only visited rules in cases when we are actually
// resolving, not probing, pseudo-element style. // resolving, not probing, pseudo-element style.
if inputs.rules.is_none() && inputs.visited_rules.is_none() { if inputs.rules.is_none() && inputs.visited_rules.is_none() {
@ -812,14 +819,16 @@ impl Stylist {
// pseudos other than before and after, so it's probably ok. // pseudos other than before and after, so it's probably ok.
// //
// (Though the flags don't indicate so!) // (Though the flags don't indicate so!)
Some(self.compute_style_with_inputs(inputs, Some(self.compute_style_with_inputs(
Some(pseudo), inputs,
guards, Some(pseudo),
parent_style, guards,
parent_style, parent_style,
parent_style, parent_style,
font_metrics, parent_style,
CascadeFlags::empty())) font_metrics,
CascadeFlags::empty(),
))
} }
/// Computes a style using the given CascadeInputs. This can be used to /// Computes a style using the given CascadeInputs. This can be used to
@ -837,17 +846,17 @@ impl Stylist {
/// ///
/// is_link should be true if we're computing style for a link; that affects /// is_link should be true if we're computing style for a link; that affects
/// how :visited handling is done. /// how :visited handling is done.
pub fn compute_style_with_inputs(&self, pub fn compute_style_with_inputs(
inputs: &CascadeInputs, &self,
pseudo: Option<&PseudoElement>, inputs: &CascadeInputs,
guards: &StylesheetGuards, pseudo: Option<&PseudoElement>,
parent_style: &ComputedValues, guards: &StylesheetGuards,
parent_style_ignoring_first_line: &ComputedValues, parent_style: &ComputedValues,
layout_parent_style: &ComputedValues, parent_style_ignoring_first_line: &ComputedValues,
font_metrics: &FontMetricsProvider, layout_parent_style: &ComputedValues,
cascade_flags: CascadeFlags) font_metrics: &FontMetricsProvider,
-> Arc<ComputedValues> cascade_flags: CascadeFlags
{ ) -> Arc<ComputedValues> {
// We need to compute visited values if we have visited rules or if our // We need to compute visited values if we have visited rules or if our
// parent has visited values. // parent has visited values.
let visited_values = if inputs.visited_rules.is_some() || parent_style.get_visited_style().is_some() { let visited_values = if inputs.visited_rules.is_some() || parent_style.get_visited_style().is_some() {
@ -877,21 +886,20 @@ impl Stylist {
layout_parent_style.get_visited_style().unwrap_or(layout_parent_style); layout_parent_style.get_visited_style().unwrap_or(layout_parent_style);
} }
let computed = Some(properties::cascade(
properties::cascade(&self.device, &self.device,
pseudo, pseudo,
rule_node, rule_node,
guards, guards,
Some(inherited_style), Some(inherited_style),
Some(inherited_style_ignoring_first_line), Some(inherited_style_ignoring_first_line),
Some(layout_parent_style_for_visited), Some(layout_parent_style_for_visited),
None, None,
None, None,
font_metrics, font_metrics,
cascade_flags, cascade_flags,
self.quirks_mode); self.quirks_mode,
))
Some(computed)
} else { } else {
None None
}; };
@ -904,18 +912,20 @@ impl Stylist {
// difficult to assert that display: contents nodes never arrive here // difficult to assert that display: contents nodes never arrive here
// (tl;dr: It doesn't apply for replaced elements and such, but the // (tl;dr: It doesn't apply for replaced elements and such, but the
// computed value is still "contents"). // computed value is still "contents").
properties::cascade(&self.device, properties::cascade(
pseudo, &self.device,
rules, pseudo,
guards, rules,
Some(parent_style), guards,
Some(parent_style_ignoring_first_line), Some(parent_style),
Some(layout_parent_style), Some(parent_style_ignoring_first_line),
visited_values, Some(layout_parent_style),
None, visited_values,
font_metrics, None,
cascade_flags, font_metrics,
self.quirks_mode) cascade_flags,
self.quirks_mode,
)
} }
fn has_rules_for_pseudo(&self, pseudo: &PseudoElement) -> bool { fn has_rules_for_pseudo(&self, pseudo: &PseudoElement) -> bool {
@ -928,14 +938,16 @@ impl Stylist {
/// ///
/// See the documentation on lazy pseudo-elements in /// See the documentation on lazy pseudo-elements in
/// docs/components/style.md /// docs/components/style.md
pub fn lazy_pseudo_rules<E>(&self, pub fn lazy_pseudo_rules<E>(
guards: &StylesheetGuards, &self,
element: &E, guards: &StylesheetGuards,
pseudo: &PseudoElement, element: &E,
is_probe: bool, pseudo: &PseudoElement,
rule_inclusion: RuleInclusion) is_probe: bool,
-> CascadeInputs rule_inclusion: RuleInclusion
where E: TElement ) -> CascadeInputs
where
E: TElement
{ {
let pseudo = pseudo.canonical(); let pseudo = pseudo.canonical();
debug_assert!(pseudo.is_lazy()); debug_assert!(pseudo.is_lazy());
@ -1009,19 +1021,24 @@ impl Stylist {
if matching_context.relevant_link_found { if matching_context.relevant_link_found {
let mut declarations = ApplicableDeclarationList::new(); let mut declarations = ApplicableDeclarationList::new();
let mut matching_context = let mut matching_context =
MatchingContext::new_for_visited(MatchingMode::ForStatelessPseudoElement, MatchingContext::new_for_visited(
None, MatchingMode::ForStatelessPseudoElement,
VisitedHandlingMode::RelevantLinkVisited, None,
self.quirks_mode); VisitedHandlingMode::RelevantLinkVisited,
self.push_applicable_declarations(element, self.quirks_mode,
Some(&pseudo), );
None,
None, self.push_applicable_declarations(
AnimationRules(None, None), element,
rule_inclusion, Some(&pseudo),
&mut declarations, None,
&mut matching_context, None,
&mut set_selector_flags); AnimationRules(None, None),
rule_inclusion,
&mut declarations,
&mut matching_context,
&mut set_selector_flags
);
if !declarations.is_empty() { if !declarations.is_empty() {
let rule_node = let rule_node =
self.rule_tree.insert_ordered_rules_with_important( self.rule_tree.insert_ordered_rules_with_important(
@ -1215,12 +1232,15 @@ impl Stylist {
/// Returns the applicable CSS declarations for the given element by /// Returns the applicable CSS declarations for the given element by
/// treating us as an XBL stylesheet-only stylist. /// treating us as an XBL stylesheet-only stylist.
pub fn push_applicable_declarations_as_xbl_only_stylist<E, V>(&self, pub fn push_applicable_declarations_as_xbl_only_stylist<E, V>(
element: &E, &self,
pseudo_element: Option<&PseudoElement>, element: &E,
applicable_declarations: &mut V) pseudo_element: Option<&PseudoElement>,
where E: TElement, applicable_declarations: &mut V
V: Push<ApplicableDeclarationBlock> + VecLike<ApplicableDeclarationBlock>, )
where
E: TElement,
V: Push<ApplicableDeclarationBlock> + VecLike<ApplicableDeclarationBlock>,
{ {
let mut matching_context = let mut matching_context =
MatchingContext::new(MatchingMode::Normal, None, self.quirks_mode); MatchingContext::new(MatchingMode::Normal, None, self.quirks_mode);
@ -1231,36 +1251,37 @@ impl Stylist {
// nsXBLPrototypeResources::LoadResources() loads Chrome XBL style // nsXBLPrototypeResources::LoadResources() loads Chrome XBL style
// sheets under eAuthorSheetFeatures level. // sheets under eAuthorSheetFeatures level.
if let Some(map) = self.cascade_data.per_origin.author.borrow_for_pseudo(pseudo_element) { if let Some(map) = self.cascade_data.per_origin.author.borrow_for_pseudo(pseudo_element) {
map.get_all_matching_rules(element, map.get_all_matching_rules(
&rule_hash_target, element,
applicable_declarations, &rule_hash_target,
&mut matching_context, applicable_declarations,
self.quirks_mode, &mut matching_context,
&mut dummy_flag_setter, self.quirks_mode,
CascadeLevel::XBL); &mut dummy_flag_setter,
CascadeLevel::XBL,
);
} }
} }
/// Returns the applicable CSS declarations for the given element. /// Returns the applicable CSS declarations for the given element.
/// ///
/// This corresponds to `ElementRuleCollector` in WebKit. /// This corresponds to `ElementRuleCollector` in WebKit.
///
/// The `StyleRelations` recorded in `MatchingContext` indicate hints about
/// which kind of rules have matched.
pub fn push_applicable_declarations<E, V, F>( pub fn push_applicable_declarations<E, V, F>(
&self, &self,
element: &E, element: &E,
pseudo_element: Option<&PseudoElement>, pseudo_element: Option<&PseudoElement>,
style_attribute: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>, style_attribute: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>,
smil_override: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>, smil_override: Option<ArcBorrow<Locked<PropertyDeclarationBlock>>>,
animation_rules: AnimationRules, animation_rules: AnimationRules,
rule_inclusion: RuleInclusion, rule_inclusion: RuleInclusion,
applicable_declarations: &mut V, applicable_declarations: &mut V,
context: &mut MatchingContext, context: &mut MatchingContext,
flags_setter: &mut F) flags_setter: &mut F,
where E: TElement, )
V: Push<ApplicableDeclarationBlock> + VecLike<ApplicableDeclarationBlock> + Debug, where
F: FnMut(&E, ElementSelectorFlags), E: TElement,
V: Push<ApplicableDeclarationBlock> + VecLike<ApplicableDeclarationBlock> + Debug,
F: FnMut(&E, ElementSelectorFlags),
{ {
// Gecko definitely has pseudo-elements with style attributes, like // Gecko definitely has pseudo-elements with style attributes, like
// ::-moz-color-swatch. // ::-moz-color-swatch.
@ -1278,13 +1299,15 @@ impl Stylist {
// Step 1: Normal user-agent rules. // Step 1: Normal user-agent rules.
if let Some(map) = self.cascade_data.per_origin.user_agent.borrow_for_pseudo(pseudo_element) { if let Some(map) = self.cascade_data.per_origin.user_agent.borrow_for_pseudo(pseudo_element) {
map.get_all_matching_rules(element, map.get_all_matching_rules(
&rule_hash_target, element,
applicable_declarations, &rule_hash_target,
context, applicable_declarations,
self.quirks_mode, context,
flags_setter, self.quirks_mode,
CascadeLevel::UANormal); flags_setter,
CascadeLevel::UANormal
);
} }
if pseudo_element.is_none() && !only_default_rules { if pseudo_element.is_none() && !only_default_rules {
@ -1314,13 +1337,15 @@ impl Stylist {
if rule_hash_target.matches_user_and_author_rules() { if rule_hash_target.matches_user_and_author_rules() {
// Step 3a: User normal rules. // Step 3a: User normal rules.
if let Some(map) = self.cascade_data.per_origin.user.borrow_for_pseudo(pseudo_element) { if let Some(map) = self.cascade_data.per_origin.user.borrow_for_pseudo(pseudo_element) {
map.get_all_matching_rules(element, map.get_all_matching_rules(
&rule_hash_target, element,
applicable_declarations, &rule_hash_target,
context, applicable_declarations,
self.quirks_mode, context,
flags_setter, self.quirks_mode,
CascadeLevel::UserNormal); flags_setter,
CascadeLevel::UserNormal,
);
} }
} else { } else {
debug!("skipping user rules"); debug!("skipping user rules");
@ -1328,8 +1353,10 @@ impl Stylist {
// Step 3b: XBL rules. // Step 3b: XBL rules.
let cut_off_inheritance = let cut_off_inheritance =
element.get_declarations_from_xbl_bindings(pseudo_element, element.get_declarations_from_xbl_bindings(
applicable_declarations); pseudo_element,
applicable_declarations,
);
if rule_hash_target.matches_user_and_author_rules() && !only_default_rules { if rule_hash_target.matches_user_and_author_rules() && !only_default_rules {
// Gecko skips author normal rules if cutting off inheritance. // Gecko skips author normal rules if cutting off inheritance.
@ -1337,13 +1364,15 @@ impl Stylist {
if !cut_off_inheritance { if !cut_off_inheritance {
// Step 3c: Author normal rules. // Step 3c: Author normal rules.
if let Some(map) = self.cascade_data.per_origin.author.borrow_for_pseudo(pseudo_element) { if let Some(map) = self.cascade_data.per_origin.author.borrow_for_pseudo(pseudo_element) {
map.get_all_matching_rules(element, map.get_all_matching_rules(
&rule_hash_target, element,
applicable_declarations, &rule_hash_target,
context, applicable_declarations,
self.quirks_mode, context,
flags_setter, self.quirks_mode,
CascadeLevel::AuthorNormal); flags_setter,
CascadeLevel::AuthorNormal
);
} }
} else { } else {
debug!("skipping author normal rules due to cut off inheritance"); debug!("skipping author normal rules due to cut off inheritance");
@ -1357,8 +1386,11 @@ impl Stylist {
if let Some(sa) = style_attribute { if let Some(sa) = style_attribute {
Push::push( Push::push(
applicable_declarations, applicable_declarations,
ApplicableDeclarationBlock::from_declarations(sa.clone_arc(), ApplicableDeclarationBlock::from_declarations(
CascadeLevel::StyleAttributeNormal)); sa.clone_arc(),
CascadeLevel::StyleAttributeNormal
)
);
} }
// Step 5: SMIL override. // Step 5: SMIL override.
@ -1366,8 +1398,11 @@ impl Stylist {
if let Some(so) = smil_override { if let Some(so) = smil_override {
Push::push( Push::push(
applicable_declarations, applicable_declarations,
ApplicableDeclarationBlock::from_declarations(so.clone_arc(), ApplicableDeclarationBlock::from_declarations(
CascadeLevel::SMILOverride)); so.clone_arc(),
CascadeLevel::SMILOverride
)
);
} }
// Step 6: Animations. // Step 6: Animations.
@ -1376,8 +1411,11 @@ impl Stylist {
if let Some(anim) = animation_rules.0 { if let Some(anim) = animation_rules.0 {
Push::push( Push::push(
applicable_declarations, applicable_declarations,
ApplicableDeclarationBlock::from_declarations(anim.clone(), ApplicableDeclarationBlock::from_declarations(
CascadeLevel::Animations)); anim.clone(),
CascadeLevel::Animations
)
);
} }
} else { } else {
debug!("skipping style attr and SMIL & animation rules"); debug!("skipping style attr and SMIL & animation rules");
@ -1394,8 +1432,11 @@ impl Stylist {
if let Some(anim) = animation_rules.1 { if let Some(anim) = animation_rules.1 {
Push::push( Push::push(
applicable_declarations, applicable_declarations,
ApplicableDeclarationBlock::from_declarations(anim.clone(), ApplicableDeclarationBlock::from_declarations(
CascadeLevel::Transitions)); anim.clone(),
CascadeLevel::Transitions
)
);
} }
} else { } else {
debug!("skipping transition rules"); debug!("skipping transition rules");
@ -1422,13 +1463,15 @@ impl Stylist {
/// Computes the match results of a given element against the set of /// Computes the match results of a given element against the set of
/// revalidation selectors. /// revalidation selectors.
pub fn match_revalidation_selectors<E, F>(&self, pub fn match_revalidation_selectors<E, F>(
element: &E, &self,
bloom: Option<&BloomFilter>, element: &E,
flags_setter: &mut F) bloom: Option<&BloomFilter>,
-> BitVec flags_setter: &mut F
where E: TElement, ) -> BitVec
F: FnMut(&E, ElementSelectorFlags), where
E: TElement,
F: FnMut(&E, ElementSelectorFlags),
{ {
// NB: `MatchingMode` doesn't really matter, given we don't share style // NB: `MatchingMode` doesn't really matter, given we don't share style
// between pseudos. // between pseudos.
@ -1443,13 +1486,17 @@ impl Stylist {
let mut results = BitVec::new(); let mut results = BitVec::new();
for (data, _) in self.cascade_data.iter_origins() { for (data, _) in self.cascade_data.iter_origins() {
data.selectors_for_cache_revalidation.lookup( data.selectors_for_cache_revalidation.lookup(
*element, self.quirks_mode, &mut |selector_and_hashes| { *element,
results.push(matches_selector(&selector_and_hashes.selector, self.quirks_mode,
selector_and_hashes.selector_offset, &mut |selector_and_hashes| {
Some(&selector_and_hashes.hashes), results.push(matches_selector(
element, &selector_and_hashes.selector,
&mut matching_context, selector_and_hashes.selector_offset,
flags_setter)); Some(&selector_and_hashes.hashes),
element,
&mut matching_context,
flags_setter
));
true true
} }
); );
@ -1459,17 +1506,19 @@ impl Stylist {
} }
/// Computes styles for a given declaration with parent_style. /// Computes styles for a given declaration with parent_style.
pub fn compute_for_declarations(&self, pub fn compute_for_declarations(
guards: &StylesheetGuards, &self,
parent_style: &ComputedValues, guards: &StylesheetGuards,
declarations: Arc<Locked<PropertyDeclarationBlock>>) parent_style: &ComputedValues,
-> Arc<ComputedValues> { declarations: Arc<Locked<PropertyDeclarationBlock>>,
) -> Arc<ComputedValues> {
use font_metrics::get_metrics_provider_for_product; use font_metrics::get_metrics_provider_for_product;
let v = vec![ let v = vec![ApplicableDeclarationBlock::from_declarations(
ApplicableDeclarationBlock::from_declarations(declarations.clone(), declarations.clone(),
CascadeLevel::StyleAttributeNormal) CascadeLevel::StyleAttributeNormal
]; )];
let rule_node = let rule_node =
self.rule_tree.insert_ordered_rules(v.into_iter().map(|a| a.order_and_level())); self.rule_tree.insert_ordered_rules(v.into_iter().map(|a| a.order_and_level()));
@ -1477,19 +1526,22 @@ impl Stylist {
// font styles in <canvas> via Servo_StyleSet_ResolveForDeclarations. // font styles in <canvas> via Servo_StyleSet_ResolveForDeclarations.
// It is unclear if visited styles are meaningful for this case. // It is unclear if visited styles are meaningful for this case.
let metrics = get_metrics_provider_for_product(); let metrics = get_metrics_provider_for_product();
// FIXME(emilio): the pseudo bit looks quite dubious! // FIXME(emilio): the pseudo bit looks quite dubious!
properties::cascade(&self.device, properties::cascade(
/* pseudo = */ None, &self.device,
&rule_node, /* pseudo = */ None,
guards, &rule_node,
Some(parent_style), guards,
Some(parent_style), Some(parent_style),
Some(parent_style), Some(parent_style),
None, Some(parent_style),
None, None,
&metrics, None,
CascadeFlags::empty(), &metrics,
self.quirks_mode) CascadeFlags::empty(),
self.quirks_mode,
)
} }
/// Accessor for a shared reference to the device. /// Accessor for a shared reference to the device.