Skip to content

Commit

Permalink
style: Miscellaneous servo build fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
emilio committed Jun 3, 2020
1 parent eff8f0f commit 332aec2
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions components/script/dom/document.rs
Expand Up @@ -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() {
Expand All @@ -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);
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions components/style/invalidation/element/invalidation_map.rs
Expand Up @@ -196,7 +196,7 @@ pub struct InvalidationMap {
/// A list of document state dependencies in the rules we represent.
pub document_state_selectors: Vec<DocumentStateDependency>,
/// A map of other attribute affecting selectors.
pub other_attribute_affecting_selectors: PrecomputedHashMap<Atom, SmallVec<[Dependency; 1]>>,
pub other_attribute_affecting_selectors: PrecomputedHashMap<LocalName, SmallVec<[Dependency; 1]>>,
}

impl InvalidationMap {
Expand Down Expand Up @@ -461,7 +461,6 @@ impl<'a> SelectorVisitor for SelectorDependencyCollector<'a> {
}

fn visit_simple_selector(&mut self, s: &Component<SelectorImpl>) -> bool {
#[cfg(feature = "gecko")]
use crate::selector_parser::NonTSPseudoClass;

match *s {
Expand Down
3 changes: 2 additions & 1 deletion components/style/matching.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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();
Expand Down
Expand Up @@ -68,8 +68,7 @@ pub type AnimationValueMap = FxHashMap<LonghandId, AnimationValue>;
///
/// 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:
Expand Down Expand Up @@ -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:
Expand All @@ -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<T: Clone>(this: &T, other: &T, procedure: Procedure) -> Result<T, ()> {
Expand Down
9 changes: 6 additions & 3 deletions components/style/selector_map.rs
Expand Up @@ -278,9 +278,12 @@ impl SelectorMap<Rule> {
}

impl<T: SelectorMapEntry> SelectorMap<T> {
/// 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
Expand Down
29 changes: 16 additions & 13 deletions components/style/servo/selector_parser.rs
Expand Up @@ -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<ElementState>,
/// The set of stored attributes and its values.
pub attrs: Option<Vec<(AttrIdentifier, AttrValue)>>,
/// 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<LocalName>,
/// Whether the class attribute changed or not.
pub class_changed: bool,
/// Whether the id attribute changed or not.
Expand All @@ -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.
Expand All @@ -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<F>(&self, mut callback: F)
where
F: FnMut(&LocalName),
{
for name in &self.changed_attrs {
callback(name)
}
}

fn any_attr_ignore_ns<F>(&self, name: &LocalName, mut f: F) -> bool
where
F: FnMut(&AttrValue) -> bool,
Expand Down
1 change: 0 additions & 1 deletion components/style/shared_lock.rs
Expand Up @@ -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};
Expand Down
3 changes: 1 addition & 2 deletions components/style/values/animated/color.rs
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/computed/align.rs
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/generics/flex.rs
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion components/style/values/generics/length.rs
Expand Up @@ -174,13 +174,13 @@ impl<LengthPercentage> Size<LengthPercentage> {

/// 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,
Expand Down
4 changes: 2 additions & 2 deletions components/style_traits/dom.rs
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions components/url/lib.rs
Expand Up @@ -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;
Expand All @@ -34,7 +33,7 @@ pub use url::Host;
pub struct ServoUrl(#[ignore_malloc_size_of = "Arc"] Arc<Url>);

impl ToShmem for ServoUrl {
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> ManuallyDrop<Self> {
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> to_shmem::Result<Self> {
unimplemented!("If servo wants to share stylesheets across processes, ToShmem for Url must be implemented")
}
}
Expand Down

0 comments on commit 332aec2

Please sign in to comment.