Stop using associated types for the concrete ElementSnapshot implementation.

MozReview-Commit-ID: LS23s2RbMBg
This commit is contained in:
Bobby Holley 2016-11-02 13:17:34 -07:00
parent 9588065120
commit b69fdad8e4
9 changed files with 28 additions and 30 deletions

View file

@ -94,7 +94,7 @@ use style::attr::{AttrIdentifier, AttrValue, LengthOrPercentageOrAuto};
use style::element_state::*; use style::element_state::*;
use style::media_queries::MediaQueryList; use style::media_queries::MediaQueryList;
use style::properties::PropertyDeclarationBlock; use style::properties::PropertyDeclarationBlock;
use style::selector_impl::{ElementSnapshot, PseudoElement}; use style::selector_impl::{PseudoElement, Snapshot};
use style::values::specified::Length; use style::values::specified::Length;
use time::Duration; use time::Duration;
use url::Origin as UrlOrigin; use url::Origin as UrlOrigin;
@ -346,7 +346,7 @@ no_jsmanaged_fields!(DOMString);
no_jsmanaged_fields!(Mime); no_jsmanaged_fields!(Mime);
no_jsmanaged_fields!(AttrIdentifier); no_jsmanaged_fields!(AttrIdentifier);
no_jsmanaged_fields!(AttrValue); no_jsmanaged_fields!(AttrValue);
no_jsmanaged_fields!(ElementSnapshot); no_jsmanaged_fields!(Snapshot);
no_jsmanaged_fields!(HttpsState); no_jsmanaged_fields!(HttpsState);
no_jsmanaged_fields!(Request); no_jsmanaged_fields!(Request);
no_jsmanaged_fields!(SharedRt); no_jsmanaged_fields!(SharedRt);

View file

@ -125,7 +125,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant}; use std::time::{Duration, Instant};
use style::attr::AttrValue; use style::attr::AttrValue;
use style::context::ReflowGoal; use style::context::ReflowGoal;
use style::selector_impl::ElementSnapshot; use style::selector_impl::Snapshot;
use style::str::{split_html_space_chars, str_join}; use style::str::{split_html_space_chars, str_join};
use style::stylesheets::Stylesheet; use style::stylesheets::Stylesheet;
use time; use time;
@ -236,7 +236,7 @@ pub struct Document {
appropriate_template_contents_owner_document: MutNullableHeap<JS<Document>>, appropriate_template_contents_owner_document: MutNullableHeap<JS<Document>>,
/// For each element that has had a state or attribute change since the last restyle, /// For each element that has had a state or attribute change since the last restyle,
/// track the original condition of the element. /// track the original condition of the element.
modified_elements: DOMRefCell<HashMap<JS<Element>, ElementSnapshot>>, modified_elements: DOMRefCell<HashMap<JS<Element>, Snapshot>>,
/// This flag will be true if layout suppressed a reflow attempt that was /// This flag will be true if layout suppressed a reflow attempt that was
/// needed in order for the page to be painted. /// needed in order for the page to be painted.
needs_paint: Cell<bool>, needs_paint: Cell<bool>,
@ -1708,7 +1708,7 @@ pub enum DocumentSource {
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub trait LayoutDocumentHelpers { pub trait LayoutDocumentHelpers {
unsafe fn is_html_document_for_layout(&self) -> bool; unsafe fn is_html_document_for_layout(&self) -> bool;
unsafe fn drain_modified_elements(&self) -> Vec<(LayoutJS<Element>, ElementSnapshot)>; unsafe fn drain_modified_elements(&self) -> Vec<(LayoutJS<Element>, Snapshot)>;
unsafe fn needs_paint_from_layout(&self); unsafe fn needs_paint_from_layout(&self);
unsafe fn will_paint(&self); unsafe fn will_paint(&self);
} }
@ -1722,7 +1722,7 @@ impl LayoutDocumentHelpers for LayoutJS<Document> {
#[inline] #[inline]
#[allow(unrooted_must_root)] #[allow(unrooted_must_root)]
unsafe fn drain_modified_elements(&self) -> Vec<(LayoutJS<Element>, ElementSnapshot)> { unsafe fn drain_modified_elements(&self) -> Vec<(LayoutJS<Element>, Snapshot)> {
let mut elements = (*self.unsafe_get()).modified_elements.borrow_mut_for_layout(); let mut elements = (*self.unsafe_get()).modified_elements.borrow_mut_for_layout();
let result = elements.drain().map(|(k, v)| (k.to_layout(), v)).collect(); let result = elements.drain().map(|(k, v)| (k.to_layout(), v)).collect();
result result
@ -1970,7 +1970,7 @@ impl Document {
let mut map = self.modified_elements.borrow_mut(); let mut map = self.modified_elements.borrow_mut();
let snapshot = map.entry(JS::from_ref(el)) let snapshot = map.entry(JS::from_ref(el))
.or_insert_with(|| { .or_insert_with(|| {
ElementSnapshot::new(el.html_element_in_html_document()) Snapshot::new(el.html_element_in_html_document())
}); });
if snapshot.state.is_none() { if snapshot.state.is_none() {
snapshot.state = Some(el.state()); snapshot.state = Some(el.state());
@ -1981,7 +1981,7 @@ impl Document {
let mut map = self.modified_elements.borrow_mut(); let mut map = self.modified_elements.borrow_mut();
let mut snapshot = map.entry(JS::from_ref(el)) let mut snapshot = map.entry(JS::from_ref(el))
.or_insert_with(|| { .or_insert_with(|| {
ElementSnapshot::new(el.html_element_in_html_document()) Snapshot::new(el.html_element_in_html_document())
}); });
if snapshot.attrs.is_none() { if snapshot.attrs.is_none() {
let attrs = el.attrs() let attrs = el.attrs()

View file

@ -66,7 +66,7 @@ use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthe
use style::dom::{TRestyleDamage, UnsafeNode}; use style::dom::{TRestyleDamage, UnsafeNode};
use style::element_state::*; use style::element_state::*;
use style::properties::{ComputedValues, PropertyDeclarationBlock}; use style::properties::{ComputedValues, PropertyDeclarationBlock};
use style::selector_impl::{ElementSnapshot, NonTSPseudoClass, PseudoElement, ServoSelectorImpl}; use style::selector_impl::{NonTSPseudoClass, PseudoElement, ServoSelectorImpl, Snapshot};
use style::selector_matching::ApplicableDeclarationBlock; use style::selector_matching::ApplicableDeclarationBlock;
use style::sink::Push; use style::sink::Push;
use style::str::is_whitespace; use style::str::is_whitespace;
@ -382,7 +382,7 @@ impl<'ld> TDocument for ServoLayoutDocument<'ld> {
self.as_node().children().find(ServoLayoutNode::is_element) self.as_node().children().find(ServoLayoutNode::is_element)
} }
fn drain_modified_elements(&self) -> Vec<(ServoLayoutElement<'ld>, ElementSnapshot)> { fn drain_modified_elements(&self) -> Vec<(ServoLayoutElement<'ld>, Snapshot)> {
let elements = unsafe { self.document.drain_modified_elements() }; let elements = unsafe { self.document.drain_modified_elements() };
elements.into_iter().map(|(el, snapshot)| (ServoLayoutElement::from_layout_js(el), snapshot)).collect() elements.into_iter().map(|(el, snapshot)| (ServoLayoutElement::from_layout_js(el), snapshot)).collect()
} }

View file

@ -14,7 +14,7 @@ use parking_lot::RwLock;
use properties::{ComputedValues, PropertyDeclarationBlock}; use properties::{ComputedValues, PropertyDeclarationBlock};
use properties::longhands::display::computed_value as display; use properties::longhands::display::computed_value as display;
use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint}; use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint};
use selector_impl::{ElementExt, PseudoElement}; use selector_impl::{ElementExt, PseudoElement, Snapshot};
use selector_matching::ApplicableDeclarationBlock; use selector_matching::ApplicableDeclarationBlock;
use sink::Push; use sink::Push;
use std::fmt::Debug; use std::fmt::Debug;
@ -159,8 +159,7 @@ pub trait TDocument : Sized + Copy + Clone {
fn root_node(&self) -> Option<Self::ConcreteNode>; fn root_node(&self) -> Option<Self::ConcreteNode>;
fn drain_modified_elements(&self) -> Vec<(Self::ConcreteElement, fn drain_modified_elements(&self) -> Vec<(Self::ConcreteElement, Snapshot)>;
<Self::ConcreteElement as ElementExt>::Snapshot)>;
fn needs_paint_from_layout(&self); fn needs_paint_from_layout(&self);
fn will_paint(&self); fn will_paint(&self);

View file

@ -691,8 +691,6 @@ impl<'le> ::selectors::MatchAttr for GeckoElement<'le> {
} }
impl<'le> ElementExt for GeckoElement<'le> { impl<'le> ElementExt for GeckoElement<'le> {
type Snapshot = GeckoElementSnapshot;
#[inline] #[inline]
fn is_link(&self) -> bool { fn is_link(&self) -> bool {
self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink) self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink)

View file

@ -8,7 +8,7 @@ use Atom;
use element_state::*; use element_state::*;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
use selector_impl::{AttrValue, ElementExt, NonTSPseudoClass, TheSelectorImpl}; use selector_impl::{AttrValue, ElementExt, NonTSPseudoClass, Snapshot, TheSelectorImpl};
use selectors::{Element, MatchAttr}; use selectors::{Element, MatchAttr};
use selectors::matching::{MatchingReason, StyleRelations}; use selectors::matching::{MatchingReason, StyleRelations};
use selectors::matching::matches_complex_selector; use selectors::matching::matches_complex_selector;
@ -85,7 +85,7 @@ struct ElementWrapper<'a, E>
where E: ElementExt where E: ElementExt
{ {
element: E, element: E,
snapshot: Option<&'a E::Snapshot>, snapshot: Option<&'a Snapshot>,
} }
impl<'a, E> ElementWrapper<'a, E> impl<'a, E> ElementWrapper<'a, E>
@ -95,7 +95,7 @@ impl<'a, E> ElementWrapper<'a, E>
ElementWrapper { element: el, snapshot: None } ElementWrapper { element: el, snapshot: None }
} }
pub fn new_with_snapshot(el: E, snapshot: &'a E::Snapshot) -> ElementWrapper<'a, E> { pub fn new_with_snapshot(el: E, snapshot: &'a Snapshot) -> ElementWrapper<'a, E> {
ElementWrapper { element: el, snapshot: Some(snapshot) } ElementWrapper { element: el, snapshot: Some(snapshot) }
} }
} }
@ -424,7 +424,7 @@ impl DependencySet {
} }
pub fn compute_hint<E>(&self, el: &E, pub fn compute_hint<E>(&self, el: &E,
snapshot: &E::Snapshot, snapshot: &Snapshot,
current_state: ElementState) current_state: ElementState)
-> RestyleHint -> RestyleHint
where E: ElementExt + Clone where E: ElementExt + Clone

View file

@ -5,7 +5,6 @@
//! The pseudo-classes and pseudo-elements supported by the style system. //! The pseudo-classes and pseudo-elements supported by the style system.
use matching::{common_style_affecting_attributes, CommonStyleAffectingAttributeMode}; use matching::{common_style_affecting_attributes, CommonStyleAffectingAttributeMode};
use restyle_hints;
use selectors::Element; use selectors::Element;
use selectors::parser::{AttrSelector, SelectorImpl}; use selectors::parser::{AttrSelector, SelectorImpl};
@ -14,14 +13,20 @@ pub type AttrValue = <TheSelectorImpl as SelectorImpl>::AttrValue;
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
pub use servo_selector_impl::*; pub use servo_selector_impl::*;
#[cfg(feature = "servo")]
pub use servo_selector_impl::{ServoSelectorImpl as TheSelectorImpl, ServoElementSnapshot as ElementSnapshot};
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use gecko::selector_impl::*; pub use gecko::selector_impl::*;
#[cfg(feature = "servo")]
pub use servo_selector_impl::ServoSelectorImpl as TheSelectorImpl;
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use gecko::selector_impl::{GeckoSelectorImpl as TheSelectorImpl}; pub use gecko::selector_impl::GeckoSelectorImpl as TheSelectorImpl;
#[cfg(feature = "servo")]
pub use servo_selector_impl::ServoElementSnapshot as Snapshot;
#[cfg(feature = "gecko")]
pub use gecko::snapshot::GeckoElementSnapshot as Snapshot;
/// This function determines if a pseudo-element is eagerly cascaded or not. /// This function determines if a pseudo-element is eagerly cascaded or not.
/// ///
@ -71,8 +76,6 @@ impl PseudoElementCascadeType {
} }
pub trait ElementExt: Element<Impl=TheSelectorImpl> { pub trait ElementExt: Element<Impl=TheSelectorImpl> {
type Snapshot: restyle_hints::ElementSnapshot + 'static;
fn is_link(&self) -> bool; fn is_link(&self) -> bool;
} }

View file

@ -16,7 +16,7 @@ use properties::{PropertyDeclaration, PropertyDeclarationBlock};
use quickersort::sort_by; use quickersort::sort_by;
use restyle_hints::{RestyleHint, DependencySet}; use restyle_hints::{RestyleHint, DependencySet};
use rule_tree::{RuleTree, StrongRuleNode, StyleSource}; use rule_tree::{RuleTree, StrongRuleNode, StyleSource};
use selector_impl::{ElementExt, TheSelectorImpl, PseudoElement}; use selector_impl::{ElementExt, TheSelectorImpl, PseudoElement, Snapshot};
use selectors::Element; use selectors::Element;
use selectors::bloom::BloomFilter; use selectors::bloom::BloomFilter;
use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS}; use selectors::matching::{AFFECTED_BY_STYLE_ATTRIBUTE, AFFECTED_BY_PRESENTATIONAL_HINTS};
@ -611,7 +611,7 @@ impl Stylist {
} }
pub fn compute_restyle_hint<E>(&self, element: &E, pub fn compute_restyle_hint<E>(&self, element: &E,
snapshot: &E::Snapshot, snapshot: &Snapshot,
// NB: We need to pass current_state as an argument because // NB: We need to pass current_state as an argument because
// selectors::Element doesn't provide access to ElementState // selectors::Element doesn't provide access to ElementState
// directly, and computing it from the ElementState would be // directly, and computing it from the ElementState would be

View file

@ -384,8 +384,6 @@ impl MatchAttrGeneric for ServoElementSnapshot {
} }
impl<E: Element<Impl=TheSelectorImpl>> ElementExt for E { impl<E: Element<Impl=TheSelectorImpl>> ElementExt for E {
type Snapshot = ServoElementSnapshot;
fn is_link(&self) -> bool { fn is_link(&self) -> bool {
self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink) self.match_non_ts_pseudo_class(NonTSPseudoClass::AnyLink)
} }