diff options
-rw-r--r-- | components/style/properties/cascade.rs | 150 |
1 files changed, 75 insertions, 75 deletions
diff --git a/components/style/properties/cascade.rs b/components/style/properties/cascade.rs index 8fbccd1d97f..2fefd0ba0fd 100644 --- a/components/style/properties/cascade.rs +++ b/components/style/properties/cascade.rs @@ -10,21 +10,23 @@ use crate::dom::TElement; use crate::font_metrics::FontMetricsProvider; use crate::logical_geometry::WritingMode; use crate::media_queries::Device; -use crate::properties::{ComputedValues, StyleBuilder, Importance}; -use crate::properties::{LonghandId, LonghandIdSet, CSSWideKeyword, PropertyFlags}; -use crate::properties::{PropertyDeclaration, PropertyDeclarationId, DeclarationImportanceIterator}; -use crate::properties::{CASCADE_PROPERTY, ComputedValueFlags}; +use crate::properties::{CSSWideKeyword, LonghandId, LonghandIdSet, PropertyFlags}; +use crate::properties::{ComputedValueFlags, CASCADE_PROPERTY}; +use crate::properties::{ComputedValues, Importance, StyleBuilder}; +use crate::properties::{ + DeclarationImportanceIterator, PropertyDeclaration, PropertyDeclarationId, +}; use crate::rule_cache::{RuleCache, RuleCacheConditions}; use crate::rule_tree::StrongRuleNode; use crate::selector_parser::PseudoElement; +use crate::shared_lock::StylesheetGuards; +use crate::style_adjuster::StyleAdjuster; use crate::stylesheets::{Origin, PerOrigin}; +use crate::values::{computed, specified}; use servo_arc::Arc; -use crate::shared_lock::StylesheetGuards; use smallvec::SmallVec; use std::borrow::Cow; use std::cell::RefCell; -use crate::style_adjuster::StyleAdjuster; -use crate::values::{computed, specified}; /// We split the cascade in two phases: 'early' properties, and 'late' /// properties. @@ -121,7 +123,11 @@ struct DeclarationIterator<'a> { impl<'a> DeclarationIterator<'a> { #[inline] - fn new(rule_node: &'a StrongRuleNode, guards: &'a StylesheetGuards, pseudo: Option<&PseudoElement>) -> Self { + fn new( + rule_node: &'a StrongRuleNode, + guards: &'a StylesheetGuards, + pseudo: Option<&PseudoElement>, + ) -> Self { let restriction = pseudo.and_then(|p| p.property_restriction()); let mut iter = Self { guards, @@ -148,7 +154,6 @@ impl<'a> DeclarationIterator<'a> { None => DeclarationImportanceIterator::default(), }; } - } impl<'a> Iterator for DeclarationIterator<'a> { @@ -282,10 +287,7 @@ where let mut declarations = SmallVec::<[(&_, Origin); 32]>::new(); let custom_properties = { - let mut builder = CustomPropertiesBuilder::new( - inherited_style.custom_properties(), - device, - ); + let mut builder = CustomPropertiesBuilder::new(inherited_style.custom_properties(), device); for (declaration, origin) in iter { declarations.push((declaration, origin)); @@ -297,9 +299,7 @@ where builder.build() }; - - let is_root_element = - pseudo.is_none() && element.map_or(false, |e| e.is_root()); + let is_root_element = pseudo.is_none() && element.map_or(false, |e| e.is_root()); let mut context = computed::Context { // We'd really like to own the rules here to avoid refcount traffic, but @@ -326,8 +326,10 @@ where let using_cached_reset_properties = { let mut cascade = Cascade::new(&mut context, cascade_mode); - cascade - .apply_properties::<EarlyProperties, _>(ApplyResetProperties::Yes, declarations.iter().cloned()); + cascade.apply_properties::<EarlyProperties, _>( + ApplyResetProperties::Yes, + declarations.iter().cloned(), + ); cascade.compute_visited_style_if_needed( element, @@ -376,7 +378,7 @@ where /// given initial value if nothing in other origins did override it. /// /// This is a bit of a clunky way of achieving this. -type DeclarationsToApplyUnlessOverriden = SmallVec::<[PropertyDeclaration; 2]>; +type DeclarationsToApplyUnlessOverriden = SmallVec<[PropertyDeclaration; 2]>; fn tweak_when_ignoring_colors( builder: &StyleBuilder, @@ -399,7 +401,9 @@ fn tweak_when_ignoring_colors( // Don't override background-color on ::-moz-color-swatch. It is set as an // author style (via the style attribute), but it's pretty important for it // to show up for obvious reasons :) - if builder.pseudo.map_or(false, |p| p.is_color_swatch()) && longhand_id == LonghandId::BackgroundColor { + if builder.pseudo.map_or(false, |p| p.is_color_swatch()) && + longhand_id == LonghandId::BackgroundColor + { return; } @@ -442,11 +446,10 @@ fn tweak_when_ignoring_colors( if alpha != 0 { let mut color = builder.device.default_background_color(); color.alpha = alpha; - declarations_to_apply_unless_overriden.push( - PropertyDeclaration::BackgroundColor(color.into()) - ) + declarations_to_apply_unless_overriden + .push(PropertyDeclaration::BackgroundColor(color.into())) } - } + }, PropertyDeclaration::Color(ref color) => { // We honor color: transparent, and "revert-or-initial" otherwise. if alpha_channel(&color.0) == 0 { @@ -457,9 +460,9 @@ fn tweak_when_ignoring_colors( // the default color. Otherwise just let it inherit through. if builder.get_parent_inherited_text().clone_color().alpha == 0 { let color = builder.device.default_color(); - declarations_to_apply_unless_overriden.push( - PropertyDeclaration::Color(specified::ColorPropertyValue(color.into())) - ) + declarations_to_apply_unless_overriden.push(PropertyDeclaration::Color( + specified::ColorPropertyValue(color.into()), + )) } }, // We honor url background-images if backplating. @@ -475,8 +478,8 @@ fn tweak_when_ignoring_colors( _ => {}, } - *declaration.to_mut() = PropertyDeclaration::css_wide_keyword(longhand_id, CSSWideKeyword::Revert); - + *declaration.to_mut() = + PropertyDeclaration::css_wide_keyword(longhand_id, CSSWideKeyword::Revert); } struct Cascade<'a, 'b: 'a> { @@ -542,11 +545,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { } #[inline(always)] - fn apply_declaration( - &mut self, - longhand_id: LonghandId, - declaration: &PropertyDeclaration, - ) { + fn apply_declaration(&mut self, longhand_id: LonghandId, declaration: &PropertyDeclaration) { // We could (and used to) use a pattern match here, but that bloats this // function to over 100K of compiled code! // @@ -574,8 +573,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { ); let ignore_colors = !self.context.builder.device.use_document_colors(); - let mut declarations_to_apply_unless_overriden = - DeclarationsToApplyUnlessOverriden::new(); + let mut declarations_to_apply_unless_overriden = DeclarationsToApplyUnlessOverriden::new(); for (declaration, origin) in declarations { let declaration_id = declaration.id(); @@ -604,7 +602,11 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { continue; } - if self.reverted.borrow_for_origin(&origin).contains(physical_longhand_id) { + if self + .reverted + .borrow_for_origin(&origin) + .contains(physical_longhand_id) + { continue; } @@ -654,13 +656,11 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { self.author_specified.insert(physical_longhand_id); } - let unset = css_wide_keyword.map_or(false, |css_wide_keyword| { - match css_wide_keyword { - CSSWideKeyword::Unset => true, - CSSWideKeyword::Inherit => inherited, - CSSWideKeyword::Initial => !inherited, - CSSWideKeyword::Revert => unreachable!(), - } + let unset = css_wide_keyword.map_or(false, |css_wide_keyword| match css_wide_keyword { + CSSWideKeyword::Unset => true, + CSSWideKeyword::Inherit => inherited, + CSSWideKeyword::Initial => !inherited, + CSSWideKeyword::Revert => unreachable!(), }); if unset { @@ -756,7 +756,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // styles, we cache the unvisited style instead. We still do // need to set the caching dependencies properly if present // though, so the cache conditions need to match. - /* rule_cache = */ None, + None, // rule_cache &mut *self.context.rule_cache_conditions.borrow_mut(), element, ); @@ -775,13 +775,18 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { if let Some(svg) = builder.get_svg_if_mutated() { svg.fill_arrays(); } - } - if self.author_specified.contains_any(LonghandIdSet::border_background_properties()) { + if self + .author_specified + .contains_any(LonghandIdSet::border_background_properties()) + { builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_BORDER_BACKGROUND); } - if self.author_specified.contains_any(LonghandIdSet::padding_properties()) { + if self + .author_specified + .contains_any(LonghandIdSet::padding_properties()) + { builder.add_flags(ComputedValueFlags::HAS_AUTHOR_SPECIFIED_PADDING); } @@ -818,8 +823,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // // Note that all the properties involved are non-inherited, so we don't // need to do anything else other than just copying the bits over. - let reset_props_bits = - ComputedValueFlags::HAS_AUTHOR_SPECIFIED_BORDER_BACKGROUND | + let reset_props_bits = ComputedValueFlags::HAS_AUTHOR_SPECIFIED_BORDER_BACKGROUND | ComputedValueFlags::HAS_AUTHOR_SPECIFIED_PADDING; builder.add_flags(cached_style.flags & reset_props_bits); @@ -838,8 +842,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { use crate::gecko_bindings::bindings; use crate::values::computed::font::GenericFontFamily; - if !self.seen.contains(LonghandId::XLang) && - !self.seen.contains(LonghandId::FontFamily) { + if !self.seen.contains(LonghandId::XLang) && !self.seen.contains(LonghandId::FontFamily) { return; } @@ -851,7 +854,10 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // System fonts are all right, and should have the default font type // set to none already, so bail out early. if font.mFont.systemFont { - debug_assert_eq!(font.mFont.fontlist.mDefaultFontType, GenericFontFamily::None); + debug_assert_eq!( + font.mFont.fontlist.mDefaultFontType, + GenericFontFamily::None + ); return; } @@ -867,13 +873,12 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // and we don't have a generic family already (or we're using // cursive or fantasy, since they're ignored, see bug 789788), and // we have a generic family to actually replace it with. - let prioritize_user_fonts = - !use_document_fonts && + let prioritize_user_fonts = !use_document_fonts && matches!( font.mGenericID, GenericFontFamily::None | - GenericFontFamily::Fantasy | - GenericFontFamily::Cursive + GenericFontFamily::Fantasy | + GenericFontFamily::Cursive ) && default_font_type != GenericFontFamily::None; @@ -887,9 +892,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { let font = builder.mutate_font().gecko_mut(); font.mFont.fontlist.mDefaultFontType = default_font_type; if prioritize_user_fonts { - unsafe { - bindings::Gecko_nsStyleFont_PrioritizeUserFonts(font, default_font_type) - } + unsafe { bindings::Gecko_nsStyleFont_PrioritizeUserFonts(font, default_font_type) } } } @@ -899,8 +902,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { use crate::values::computed::ToComputedValue; use crate::values::specified; - if !self.seen.contains(LonghandId::XLang) && - !self.seen.contains(LonghandId::FontFamily) { + if !self.seen.contains(LonghandId::XLang) && !self.seen.contains(LonghandId::FontFamily) { return; } @@ -912,7 +914,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { _ => { self.context.for_non_inherited_property = None; specified::FontSize::Keyword(info).to_computed_value(self.context) - } + }, }; if font.gecko().mScriptUnconstrainedSize == new_size.size { @@ -933,9 +935,10 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { use crate::values::generics::NonNegative; if !self.seen.contains(LonghandId::XLang) && - !self.seen.contains(LonghandId::FontFamily) && - !self.seen.contains(LonghandId::MozMinFontSizeRatio) && - !self.seen.contains(LonghandId::FontSize) { + !self.seen.contains(LonghandId::FontFamily) && + !self.seen.contains(LonghandId::MozMinFontSizeRatio) && + !self.seen.contains(LonghandId::FontSize) + { return; } @@ -943,10 +946,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { let min_font_size = { let font = builder.get_font().gecko(); let min_font_size = unsafe { - bindings::Gecko_nsStyleFont_ComputeMinSize( - font, - builder.device.document(), - ) + bindings::Gecko_nsStyleFont_ComputeMinSize(font, builder.device.document()) }; if font.mFont.size.0 >= min_font_size { @@ -998,8 +998,9 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { use crate::values::generics::NonNegative; if !self.seen.contains(LonghandId::MathDepth) && - !self.seen.contains(LonghandId::MozScriptMinSize) && - !self.seen.contains(LonghandId::MozScriptSizeMultiplier) { + !self.seen.contains(LonghandId::MozScriptMinSize) && + !self.seen.contains(LonghandId::MozScriptSizeMultiplier) + { return; } @@ -1013,8 +1014,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { let font = builder.get_font().gecko(); let parent_font = builder.get_parent_font().gecko(); - let delta = - font.mMathDepth.saturating_sub(parent_font.mMathDepth); + let delta = font.mMathDepth.saturating_sub(parent_font.mMathDepth); if delta == 0 { return; @@ -1049,7 +1049,7 @@ impl<'a, 'b: 'a> Cascade<'a, 'b> { // of em units), use that instead. ( new_size.min(new_unconstrained_size.max(min)), - new_unconstrained_size + new_unconstrained_size, ) } }; |