From dda29283862481786805993b9dee7f8b37ad36b4 Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Mon, 14 Nov 2016 12:05:17 -0800 Subject: [PATCH] Remove TDocument from the style and layout crates. The style system never actually does anything with the document. This allows us to remove a bunch of stubbing on the Gecko side and streamline some things on the Servo side in future patches. --- components/layout/traversal.rs | 4 +- components/layout_thread/lib.rs | 2 +- components/script/layout_wrapper.rs | 33 ++++++--------- .../script_layout_interface/wrapper_traits.rs | 6 +-- components/style/dom.rs | 24 ++--------- components/style/gecko/wrapper.rs | 41 ++----------------- 6 files changed, 22 insertions(+), 88 deletions(-) diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs index b054568d5d5..3ec1f2f85a5 100644 --- a/components/layout/traversal.rs +++ b/components/layout/traversal.rs @@ -10,7 +10,7 @@ use display_list_builder::DisplayListBuildState; use flow::{self, PreorderFlowTraversal}; use flow::{CAN_BE_FRAGMENTED, Flow, ImmutableFlowUtils, PostorderFlowTraversal}; use gfx::display_list::OpaqueNode; -use script_layout_interface::wrapper_traits::{LayoutElement, LayoutNode, ThreadSafeLayoutNode}; +use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode}; use std::mem; use style::atomic_refcell::AtomicRefCell; use style::context::{LocalStyleContext, SharedStyleContext, StyleContext}; @@ -32,7 +32,7 @@ pub struct RecalcStyleAndConstructFlows<'lc> { #[allow(unsafe_code)] impl<'lc, N> DomTraversalContext for RecalcStyleAndConstructFlows<'lc> where N: LayoutNode + TNode, - N::ConcreteElement: LayoutElement + N::ConcreteElement: TElement { type SharedContext = SharedLayoutContext; diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 859183935b1..09061a0932f 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -103,7 +103,7 @@ use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::mpsc::{Receiver, Sender, channel}; use style::animation::Animation; use style::context::{LocalStyleContextCreationInfo, ReflowGoal, SharedStyleContext}; -use style::dom::{TDocument, TElement, TNode}; +use style::dom::{TElement, TNode}; use style::error_reporting::{ParseErrorReporter, StdoutErrorReporter}; use style::logical_geometry::LogicalPoint; use style::media_queries::{Device, MediaType}; diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index 00c7ce1413c..fb31965d45d 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -46,7 +46,7 @@ use parking_lot::RwLock; use range::Range; use script_layout_interface::{HTMLCanvasData, LayoutNodeType, SVGSVGData, TrustedNodeAddress}; use script_layout_interface::{OpaqueStyleAndLayoutData, PartialPersistentLayoutData}; -use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, GetLayoutData, LayoutElement, LayoutNode}; +use script_layout_interface::wrapper_traits::{DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode}; use script_layout_interface::wrapper_traits::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; use selectors::matching::ElementFlags; use selectors::parser::{AttrSelector, NamespaceConstraint}; @@ -61,7 +61,7 @@ use style::attr::AttrValue; use style::computed_values::display; use style::context::SharedStyleContext; use style::data::ElementData; -use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TDocument, TElement, TNode}; +use style::dom::{LayoutIterator, NodeInfo, OpaqueNode, PresentationalHintsSynthetizer, TElement, TNode}; use style::dom::{TRestyleDamage, UnsafeNode}; use style::element_state::*; use style::properties::{ComputedValues, PropertyDeclarationBlock}; @@ -112,6 +112,10 @@ impl<'ln> ServoLayoutNode<'ln> { self.node.type_id_for_layout() } } + + pub fn as_document(&self) -> Option> { + self.node.downcast().map(ServoLayoutDocument::from_layout_js) + } } impl<'ln> NodeInfo for ServoLayoutNode<'ln> { @@ -128,7 +132,6 @@ impl<'ln> NodeInfo for ServoLayoutNode<'ln> { impl<'ln> TNode for ServoLayoutNode<'ln> { type ConcreteElement = ServoLayoutElement<'ln>; - type ConcreteDocument = ServoLayoutDocument<'ln>; type ConcreteChildrenIterator = ServoChildrenIterator<'ln>; fn to_unsafe(&self) -> UnsafeNode { @@ -177,10 +180,6 @@ impl<'ln> TNode for ServoLayoutNode<'ln> { as_element(self.node) } - fn as_document(&self) -> Option> { - self.node.downcast().map(ServoLayoutDocument::from_layout_js) - } - fn needs_dirty_on_viewport_size_changed(&self) -> bool { unsafe { self.node.get_flag(DIRTY_ON_VIEWPORT_SIZE_CHANGE) } } @@ -369,34 +368,29 @@ pub struct ServoLayoutDocument<'ld> { chain: PhantomData<&'ld ()>, } -impl<'ld> TDocument for ServoLayoutDocument<'ld> { - type ConcreteNode = ServoLayoutNode<'ld>; - type ConcreteElement = ServoLayoutElement<'ld>; - +impl<'ld> ServoLayoutDocument<'ld> { fn as_node(&self) -> ServoLayoutNode<'ld> { ServoLayoutNode::from_layout_js(self.document.upcast()) } - fn root_node(&self) -> Option> { + pub fn root_node(&self) -> Option> { self.as_node().children().find(ServoLayoutNode::is_element) } - fn drain_modified_elements(&self) -> Vec<(ServoLayoutElement<'ld>, Snapshot)> { + pub fn drain_modified_elements(&self) -> Vec<(ServoLayoutElement<'ld>, Snapshot)> { let elements = unsafe { self.document.drain_modified_elements() }; elements.into_iter().map(|(el, snapshot)| (ServoLayoutElement::from_layout_js(el), snapshot)).collect() } - fn needs_paint_from_layout(&self) { + pub fn needs_paint_from_layout(&self) { unsafe { self.document.needs_paint_from_layout(); } } - fn will_paint(&self) { + pub fn will_paint(&self) { unsafe { self.document.will_paint(); } } -} -impl<'ld> ServoLayoutDocument<'ld> { - fn from_layout_js(doc: LayoutJS) -> ServoLayoutDocument<'ld> { + pub fn from_layout_js(doc: LayoutJS) -> ServoLayoutDocument<'ld> { ServoLayoutDocument { document: doc, chain: PhantomData, @@ -433,7 +427,6 @@ impl<'le> PresentationalHintsSynthetizer for ServoLayoutElement<'le> { impl<'le> TElement for ServoLayoutElement<'le> { type ConcreteNode = ServoLayoutNode<'le>; - type ConcreteDocument = ServoLayoutDocument<'le>; fn as_node(&self) -> ServoLayoutNode<'le> { ServoLayoutNode::from_layout_js(self.element.upcast()) @@ -1069,8 +1062,6 @@ impl<'le> ThreadSafeLayoutElement for ServoThreadSafeLayoutElement<'le> { } } -impl<'le> LayoutElement for ServoLayoutElement<'le> {} - /// This implementation of `::selectors::Element` is used for implementing lazy /// pseudo-elements. /// diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index 9123c0c1f45..8de7d757be1 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -18,7 +18,7 @@ use style::atomic_refcell::AtomicRefCell; use style::computed_values::display; use style::context::SharedStyleContext; use style::data::ElementData; -use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TElement, TNode}; +use style::dom::{LayoutIterator, NodeInfo, PresentationalHintsSynthetizer, TNode}; use style::dom::OpaqueNode; use style::properties::ServoComputedValues; use style::selector_impl::{PseudoElement, PseudoElementCascadeType, RestyleDamage, ServoSelectorImpl}; @@ -274,9 +274,6 @@ pub trait DangerousThreadSafeLayoutNode: ThreadSafeLayoutNode { unsafe fn dangerous_next_sibling(&self) -> Option; } -pub trait LayoutElement: Clone + Copy + Sized + Debug + GetLayoutData + TElement { -} - pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + ::selectors::Element + GetLayoutData + @@ -435,5 +432,4 @@ pub trait ThreadSafeLayoutElement: Clone + Copy + Sized + Debug + .get(&other.style_pseudo_element()).unwrap().0.clone(), } } - } diff --git a/components/style/dom.rs b/components/style/dom.rs index 388a7310ab0..7b15e820edf 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -14,7 +14,7 @@ use parking_lot::RwLock; use properties::{ComputedValues, PropertyDeclarationBlock}; use properties::longhands::display::computed_value as display; use restyle_hints::{RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS, RESTYLE_SELF, RestyleHint}; -use selector_impl::{ElementExt, PseudoElement, RestyleDamage, Snapshot}; +use selector_impl::{ElementExt, PseudoElement, RestyleDamage}; use selector_matching::ApplicableDeclarationBlock; use sink::Push; use std::fmt::Debug; @@ -105,8 +105,7 @@ impl Iterator for LayoutIterator where T: Iterator, I: NodeInfo } pub trait TNode : Sized + Copy + Clone + NodeInfo { - type ConcreteElement: TElement; - type ConcreteDocument: TDocument; + type ConcreteElement: TElement; type ConcreteChildrenIterator: Iterator; fn to_unsafe(&self) -> UnsafeNode; @@ -130,8 +129,6 @@ pub trait TNode : Sized + Copy + Clone + NodeInfo { fn as_element(&self) -> Option; - fn as_document(&self) -> Option; - fn needs_dirty_on_viewport_size_changed(&self) -> bool; unsafe fn set_dirty_on_viewport_size_changed(&self); @@ -151,28 +148,13 @@ pub trait TNode : Sized + Copy + Clone + NodeInfo { fn next_sibling(&self) -> Option; } -pub trait TDocument : Sized + Copy + Clone { - type ConcreteNode: TNode; - type ConcreteElement: TElement; - - fn as_node(&self) -> Self::ConcreteNode; - - fn root_node(&self) -> Option; - - fn drain_modified_elements(&self) -> Vec<(Self::ConcreteElement, Snapshot)>; - - fn needs_paint_from_layout(&self); - fn will_paint(&self); -} - pub trait PresentationalHintsSynthetizer { fn synthesize_presentational_hints_for_legacy_attributes(&self, hints: &mut V) where V: Push; } pub trait TElement : PartialEq + Debug + Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer { - type ConcreteNode: TNode; - type ConcreteDocument: TDocument; + type ConcreteNode: TNode; fn as_node(&self) -> Self::ConcreteNode; diff --git a/components/style/gecko/wrapper.rs b/components/style/gecko/wrapper.rs index 9adac5f269f..e84295f78cb 100644 --- a/components/style/gecko/wrapper.rs +++ b/components/style/gecko/wrapper.rs @@ -7,22 +7,20 @@ use atomic_refcell::{AtomicRef, AtomicRefCell}; use data::ElementData; -use dom::{LayoutIterator, NodeInfo, TDocument, TElement, TNode, UnsafeNode}; +use dom::{LayoutIterator, NodeInfo, TElement, TNode, UnsafeNode}; use dom::{OpaqueNode, PresentationalHintsSynthetizer}; use element_state::ElementState; use error_reporting::StdoutErrorReporter; use gecko::restyle_damage::GeckoRestyleDamage; use gecko::selector_impl::{GeckoSelectorImpl, NonTSPseudoClass, PseudoElement}; -use gecko::snapshot::GeckoElementSnapshot; use gecko::snapshot_helpers; use gecko_bindings::bindings; use gecko_bindings::bindings::{Gecko_DropStyleChildrenIterator, Gecko_MaybeCreateStyleChildrenIterator}; -use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetDocumentElement}; -use gecko_bindings::bindings::{Gecko_GetLastChild, Gecko_GetNextStyleChild}; +use gecko_bindings::bindings::{Gecko_ElementState, Gecko_GetLastChild, Gecko_GetNextStyleChild}; use gecko_bindings::bindings::{Gecko_GetServoDeclarationBlock, Gecko_IsHTMLElementInHTMLDocument}; use gecko_bindings::bindings::{Gecko_IsLink, Gecko_IsRootElement}; use gecko_bindings::bindings::{Gecko_IsUnvisitedLink, Gecko_IsVisitedLink, Gecko_Namespace}; -use gecko_bindings::bindings::{RawGeckoDocument, RawGeckoElement, RawGeckoNode}; +use gecko_bindings::bindings::{RawGeckoElement, RawGeckoNode}; use gecko_bindings::bindings::Gecko_ClassOrClassList; use gecko_bindings::bindings::Gecko_GetStyleContext; use gecko_bindings::bindings::Gecko_SetNodeFlags; @@ -79,7 +77,6 @@ impl<'ln> NodeInfo for GeckoNode<'ln> { } impl<'ln> TNode for GeckoNode<'ln> { - type ConcreteDocument = GeckoDocument<'ln>; type ConcreteElement = GeckoElement<'ln>; type ConcreteChildrenIterator = GeckoChildrenIterator<'ln>; @@ -138,10 +135,6 @@ impl<'ln> TNode for GeckoNode<'ln> { } } - fn as_document(&self) -> Option> { - unimplemented!() - } - fn can_be_fragmented(&self) -> bool { // FIXME(SimonSapin): Servo uses this to implement CSS multicol / fragmentation // Maybe this isn’t useful for Gecko? @@ -219,33 +212,6 @@ impl<'a> Iterator for GeckoChildrenIterator<'a> { } } -#[derive(Clone, Copy)] -pub struct GeckoDocument<'ld>(pub &'ld RawGeckoDocument); - -impl<'ld> TDocument for GeckoDocument<'ld> { - type ConcreteNode = GeckoNode<'ld>; - type ConcreteElement = GeckoElement<'ld>; - - fn as_node(&self) -> GeckoNode<'ld> { - unsafe { GeckoNode(&*(self.0 as *const _ as *const RawGeckoNode)) } - } - - fn root_node(&self) -> Option> { - unsafe { - Gecko_GetDocumentElement(self.0).map(|el| GeckoElement(el).as_node()) - } - } - - fn drain_modified_elements(&self) -> Vec<(GeckoElement<'ld>, GeckoElementSnapshot)> { - unimplemented!() - /* - let elements = unsafe { self.0.drain_modified_elements() }; - elements.into_iter().map(|(el, snapshot)| (ServoLayoutElement::from_layout_js(el), snapshot)).collect()*/ - } - fn will_paint(&self) { unimplemented!() } - fn needs_paint_from_layout(&self) { unimplemented!() } -} - #[derive(Clone, Copy)] pub struct GeckoElement<'le>(pub &'le RawGeckoElement); @@ -323,7 +289,6 @@ lazy_static! { impl<'le> TElement for GeckoElement<'le> { type ConcreteNode = GeckoNode<'le>; - type ConcreteDocument = GeckoDocument<'le>; fn as_node(&self) -> Self::ConcreteNode { unsafe { GeckoNode(&*(self.0 as *const _ as *const RawGeckoNode)) }