diff --git a/Cargo.lock b/Cargo.lock index 449ceba3875..a0a6ed54a51 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5329,9 +5329,9 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallbitvec" -version = "2.3.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1764fe2b30ee783bfe3b9b37b2649d8d590b3148bb12e0079715d4d5c673562e" +checksum = "797a4eaffb90d896f29698d45676f9f940a71936d7574996a7df54593ba209fa" [[package]] name = "smallvec" diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index b9af35b8cac..157829412ce 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -3331,7 +3331,7 @@ impl Document { pub fn element_state_will_change(&self, el: &Element) { let mut entry = self.ensure_pending_restyle(el); if entry.snapshot.is_none() { - entry.snapshot = Some(Snapshot::new(el.html_element_in_html_document())); + entry.snapshot = Some(Snapshot::new()); } let snapshot = entry.snapshot.as_mut().unwrap(); if snapshot.state.is_none() { @@ -3347,7 +3347,7 @@ impl Document { // could in theory do it in the DOM I think. let mut entry = self.ensure_pending_restyle(el); if entry.snapshot.is_none() { - entry.snapshot = Some(Snapshot::new(el.html_element_in_html_document())); + entry.snapshot = Some(Snapshot::new()); } if attr.local_name() == &local_name!("style") { entry.hint.insert(RestyleHint::RESTYLE_STYLE_ATTRIBUTE); @@ -3359,12 +3359,21 @@ impl Document { let snapshot = entry.snapshot.as_mut().unwrap(); if attr.local_name() == &local_name!("id") { + if snapshot.id_changed { + return; + } snapshot.id_changed = true; } else if attr.local_name() == &local_name!("class") { + if snapshot.class_changed { + return; + } snapshot.class_changed = true; } else { snapshot.other_attributes_changed = true; } + if !snapshot.changed_attrs.contains(attr.local_name()) { + snapshot.changed_attrs.push(attr.local_name().clone()); + } if snapshot.attrs.is_none() { let attrs = el .attrs() diff --git a/components/style/invalidation/element/invalidation_map.rs b/components/style/invalidation/element/invalidation_map.rs index 59143dd0025..b822e47545e 100644 --- a/components/style/invalidation/element/invalidation_map.rs +++ b/components/style/invalidation/element/invalidation_map.rs @@ -196,7 +196,7 @@ pub struct InvalidationMap { /// A list of document state dependencies in the rules we represent. pub document_state_selectors: Vec, /// A map of other attribute affecting selectors. - pub other_attribute_affecting_selectors: PrecomputedHashMap>, + pub other_attribute_affecting_selectors: PrecomputedHashMap>, } impl InvalidationMap { @@ -461,7 +461,6 @@ impl<'a> SelectorVisitor for SelectorDependencyCollector<'a> { } fn visit_simple_selector(&mut self, s: &Component) -> bool { - #[cfg(feature = "gecko")] use crate::selector_parser::NonTSPseudoClass; match *s { diff --git a/components/style/matching.rs b/components/style/matching.rs index 677f024acfa..e8c6e55520f 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -7,7 +7,6 @@ #![allow(unsafe_code)] #![deny(missing_docs)] -use crate::animation::AnimationState; use crate::computed_value_flags::ComputedValueFlags; use crate::context::{ElementCascadeInputs, QuirksMode, SelectorFlagsMap}; use crate::context::{SharedStyleContext, StyleContext}; @@ -438,6 +437,8 @@ trait PrivateMatchMethods: TElement { _restyle_hint: RestyleHint, _important_rules_changed: bool, ) { + use crate::animation::AnimationState; + let this_opaque = self.as_node().opaque(); let shared_context = context.shared; let mut animation_states = shared_context.animation_states.write(); diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 863da15d65c..f0c9c7cad78 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -68,8 +68,7 @@ pub type AnimationValueMap = FxHashMap; /// /// FIXME: We need to add a path for custom properties, but that's trivial after /// this (is a similar path to that of PropertyDeclaration). -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] -#[derive(Debug)] +#[derive(Debug, MallocSizeOf)] #[repr(u16)] pub enum AnimationValue { % for prop in data.longhands: @@ -420,6 +419,7 @@ impl AnimationValue { /// /// SERVO ONLY: This doesn't properly handle things like updating 'em' units /// when animated font-size. + #[cfg(feature = "servo")] pub fn set_in_style_for_servo(&self, style: &mut ComputedValues) { match self { % for prop in data.longhands: @@ -439,6 +439,11 @@ impl AnimationValue { % endfor } } + + /// As above, but a stub for Gecko. + #[cfg(feature = "gecko")] + pub fn set_in_style_for_servo(&self, _: &mut ComputedValues) { + } } fn animate_discrete(this: &T, other: &T, procedure: Procedure) -> Result { diff --git a/components/style/selector_map.rs b/components/style/selector_map.rs index 3c811e2e458..2088a5baab1 100644 --- a/components/style/selector_map.rs +++ b/components/style/selector_map.rs @@ -278,9 +278,12 @@ impl SelectorMap { } impl SelectorMap { - /// Inserts into the correct hash, trying id, class, localname and - /// namespace. - pub fn insert(&mut self, entry: T, quirks_mode: QuirksMode) -> Result<(), FailedAllocationError> { + /// Inserts an entry into the correct bucket(s). + pub fn insert( + &mut self, + entry: T, + quirks_mode: QuirksMode, + ) -> Result<(), FailedAllocationError> { self.count += 1; // NOTE(emilio): It'd be nice for this to be a separate function, but diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs index d8b84b13280..af4dd92fcf7 100644 --- a/components/style/servo/selector_parser.rs +++ b/components/style/servo/selector_parser.rs @@ -615,15 +615,14 @@ impl DerefMut for SnapshotMap { } /// Servo's version of an element snapshot. -#[derive(Debug)] -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] +#[derive(Debug, Default, MallocSizeOf)] pub struct ServoElementSnapshot { /// The stored state of the element. pub state: Option, /// The set of stored attributes and its values. pub attrs: Option>, - /// Whether this element is an HTML element in an HTML document. - pub is_html_element_in_html_document: bool, + /// The set of changed attributes and its values. + pub changed_attrs: Vec, /// Whether the class attribute changed or not. pub class_changed: bool, /// Whether the id attribute changed or not. @@ -634,15 +633,8 @@ pub struct ServoElementSnapshot { impl ServoElementSnapshot { /// Create an empty element snapshot. - pub fn new(is_html_element_in_html_document: bool) -> Self { - ServoElementSnapshot { - state: None, - attrs: None, - is_html_element_in_html_document: is_html_element_in_html_document, - class_changed: false, - id_changed: false, - other_attributes_changed: false, - } + pub fn new() -> Self { + Self::default() } /// Returns whether the id attribute changed or not. @@ -669,6 +661,17 @@ impl ServoElementSnapshot { .map(|&(_, ref v)| v) } + /// Executes the callback once for each attribute that changed. + #[inline] + pub fn each_attr_changed(&self, mut callback: F) + where + F: FnMut(&LocalName), + { + for name in &self.changed_attrs { + callback(name) + } + } + fn any_attr_ignore_ns(&self, name: &LocalName, mut f: F) -> bool where F: FnMut(&AttrValue) -> bool, diff --git a/components/style/shared_lock.rs b/components/style/shared_lock.rs index 107fd6d7103..d151062199f 100644 --- a/components/style/shared_lock.rs +++ b/components/style/shared_lock.rs @@ -15,7 +15,6 @@ use std::cell::UnsafeCell; use std::fmt; #[cfg(feature = "servo")] use std::mem; -use std::mem::ManuallyDrop; #[cfg(feature = "gecko")] use std::ptr; use to_shmem::{SharedMemoryBuilder, ToShmem}; diff --git a/components/style/values/animated/color.rs b/components/style/values/animated/color.rs index 14b1d0c539c..9f4fa5c52b5 100644 --- a/components/style/values/animated/color.rs +++ b/components/style/values/animated/color.rs @@ -12,8 +12,7 @@ use crate::values::generics::color::{Color as GenericColor, ComplexColorRatios}; /// /// Unlike in computed values, each component value may exceed the /// range `[0.0, 1.0]`. -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] -#[derive(Clone, Copy, Debug, PartialEq, ToAnimatedZero)] +#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToAnimatedZero)] pub struct RGBA { /// The red component. pub red: f32, diff --git a/components/style/values/computed/align.rs b/components/style/values/computed/align.rs index 893f6fcce51..5cfb53f89ee 100644 --- a/components/style/values/computed/align.rs +++ b/components/style/values/computed/align.rs @@ -35,7 +35,7 @@ pub use super::specified::{AlignSelf, JustifySelf}; /// sucks :(. /// /// See the discussion in https://bugzil.la/1384542. -#[derive(Clone, Copy, Debug, Eq, PartialEq, ToCss, ToResolvedValue)] +#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq, ToCss, ToResolvedValue)] #[repr(C)] pub struct ComputedJustifyItems { /// The specified value for the property. Can contain the bare `legacy` diff --git a/components/style/values/generics/flex.rs b/components/style/values/generics/flex.rs index adff13b5b42..85b64000f2b 100644 --- a/components/style/values/generics/flex.rs +++ b/components/style/values/generics/flex.rs @@ -5,13 +5,13 @@ //! Generic types for CSS values related to flexbox. /// A generic value for the `flex-basis` property. -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[derive( Animate, Clone, ComputeSquaredDistance, Copy, Debug, + MallocSizeOf, Parse, PartialEq, SpecifiedValueInfo, diff --git a/components/style/values/generics/length.rs b/components/style/values/generics/length.rs index 4183f40a942..bed574861cb 100644 --- a/components/style/values/generics/length.rs +++ b/components/style/values/generics/length.rs @@ -174,13 +174,13 @@ impl Size { /// A generic value for the `max-width` or `max-height` property. #[allow(missing_docs)] -#[cfg_attr(feature = "servo", derive(MallocSizeOf))] #[derive( Animate, Clone, ComputeSquaredDistance, Copy, Debug, + MallocSizeOf, PartialEq, SpecifiedValueInfo, ToAnimatedValue, diff --git a/components/style_traits/dom.rs b/components/style_traits/dom.rs index f9844519279..03d5264abf5 100644 --- a/components/style_traits/dom.rs +++ b/components/style_traits/dom.rs @@ -13,8 +13,8 @@ /// Because the script task's GC does not trace layout, node data cannot be safely stored in layout /// 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))] +#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq)] +#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))] pub struct OpaqueNode(pub usize); impl OpaqueNode { diff --git a/components/url/lib.rs b/components/url/lib.rs index 8a05837a461..f58bbbad3ff 100644 --- a/components/url/lib.rs +++ b/components/url/lib.rs @@ -20,7 +20,6 @@ pub use crate::origin::{ImmutableOrigin, MutableOrigin, OpaqueOrigin}; use std::collections::hash_map::DefaultHasher; use std::fmt; use std::hash::Hasher; -use std::mem::ManuallyDrop; use std::net::IpAddr; use std::ops::{Index, Range, RangeFrom, RangeFull, RangeTo}; use std::path::Path; @@ -34,7 +33,7 @@ pub use url::Host; pub struct ServoUrl(#[ignore_malloc_size_of = "Arc"] Arc); impl ToShmem for ServoUrl { - fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop { + fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> to_shmem::Result { unimplemented!("If servo wants to share stylesheets across processes, ToShmem for Url must be implemented") } }