From 5ac12b5df4406dbde1ceeb6be36be5c3162401a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 Jan 2018 21:49:18 +0100 Subject: style: Make the TElement type arrive to the `cascade` function. Not super-proud of this one, but it's the easiest way I could think of. The changeset looks bigger than what it is, because while at it I've rewrapped a fair amount of functions around to use proper block indentation. Alternatives are parameterizing Stylist by , which is not fun, or moving the concrete element from layout_thread to layout, but that implies layout depending on script, which isn't fun either. Other alternative is implementing an empty enum and making anon boxes work on it. It has the advantage of removing the annoying type parameter, but the disadvantage of instantiating `cascade` twice, which isn't great, and having to maintain all the boilerplate of a `TElement` implementation that just does nothing. --- components/script_layout_interface/lib.rs | 1 + components/script_layout_interface/wrapper_traits.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'components/script_layout_interface') diff --git a/components/script_layout_interface/lib.rs b/components/script_layout_interface/lib.rs index 0538aabafd0..45c82ee1089 100644 --- a/components/script_layout_interface/lib.rs +++ b/components/script_layout_interface/lib.rs @@ -7,6 +7,7 @@ //! to depend on script. #![deny(unsafe_code)] +#![feature(associated_type_defaults)] extern crate app_units; extern crate atomic_refcell; diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index dc1f5db4c54..17a9172cd71 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -19,7 +19,7 @@ use std::fmt::Debug; use style::attr::AttrValue; use style::context::SharedStyleContext; use style::data::ElementData; -use style::dom::{LayoutIterator, NodeInfo, TNode}; +use style::dom::{LayoutIterator, NodeInfo, TElement, TNode}; use style::dom::OpaqueNode; use style::font_metrics::ServoMetricsProvider; use style::properties::{CascadeFlags, ComputedValues}; @@ -148,6 +148,8 @@ impl Iterator for TreeIterator /// node does not allow any parents or siblings of nodes to be accessed, to avoid races. pub trait ThreadSafeLayoutNode: Clone + Copy + Debug + GetLayoutData + NodeInfo + PartialEq + Sized { type ConcreteNode: LayoutNode; + type ConcreteElement: TElement = ::ConcreteElement; + type ConcreteThreadSafeLayoutElement: ThreadSafeLayoutElement + ::selectors::Element; @@ -291,6 +293,10 @@ pub trait ThreadSafeLayoutElement { type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode; + /// This type alias is just a hack to avoid writing the monstrosity after it + /// twice. + type ConcreteElement: TElement = ::ConcreteElement; + fn as_node(&self) -> Self::ConcreteThreadSafeLayoutNode; /// Creates a new `ThreadSafeLayoutElement` for the same `LayoutElement` @@ -307,8 +313,7 @@ pub trait ThreadSafeLayoutElement /// /// We need this so that the functions defined on this trait can call /// lazily_compute_pseudo_element_style, which operates on TElement. - unsafe fn unsafe_get(self) -> - <::ConcreteNode as TNode>::ConcreteElement; + unsafe fn unsafe_get(self) -> Self::ConcreteElement; #[inline] fn get_attr(&self, namespace: &Namespace, name: &LocalName) -> Option<&str>; @@ -382,7 +387,7 @@ pub trait ThreadSafeLayoutElement .unwrap().clone() }, PseudoElementCascadeType::Precomputed => { - context.stylist.precomputed_values_for_pseudo( + context.stylist.precomputed_values_for_pseudo::( &context.guards, &style_pseudo, Some(data.styles.primary()), -- cgit v1.2.3 From 104f5c2553606d0b26d7cf2ad9b90eb2efd94792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 Jan 2018 23:50:40 +0100 Subject: style: Derive debug for CascadeInputs. It no longer has anything than rules. --- components/script_layout_interface/wrapper_traits.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'components/script_layout_interface') diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index 17a9172cd71..ffdc9aa95ed 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -148,7 +148,7 @@ impl Iterator for TreeIterator /// node does not allow any parents or siblings of nodes to be accessed, to avoid races. pub trait ThreadSafeLayoutNode: Clone + Copy + Debug + GetLayoutData + NodeInfo + PartialEq + Sized { type ConcreteNode: LayoutNode; - type ConcreteElement: TElement = ::ConcreteElement; + type ConcreteElement: TElement; type ConcreteThreadSafeLayoutElement: ThreadSafeLayoutElement @@ -293,9 +293,11 @@ pub trait ThreadSafeLayoutElement { type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode; - /// This type alias is just a hack to avoid writing the monstrosity after it - /// twice. - type ConcreteElement: TElement = ::ConcreteElement; + /// This type alias is just a work-around to avoid writing + /// + /// ::ConcreteElement + /// + type ConcreteElement: TElement; fn as_node(&self) -> Self::ConcreteThreadSafeLayoutNode; -- cgit v1.2.3 From cd04664fb987ebfab063cbbff1a2516bd16b8cd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 22 Jan 2018 23:53:03 +0100 Subject: style: Use CascadeFlags for what they're for. Now that we have an Element around on cascade, we can stop using the cascade flags mechanism to pass various element-related state, like "is this element the root", or "should it use the item-based display fixup". That fixes handwaviness in the handling of those flags from style reparenting, and code duplication to handle tricky stuff like :visited. There are a number of other changes that are worth noticing: * skip_root_and_item_based_display_fixup is renamed to skip_item_display_fixup: TElement::is_root() already implies being the document element, which by definition is not native anonymous and not a pseudo-element. Thus, you never get fixed-up if your NAC or a pseudo, which is what the code tried to avoid, so the only fixup with a point is the item one, which is necessary. * The pseudo-element probing code was refactored to return early a Option::::None, which is nicer than what it was doing. * The visited_links_enabled check has moved to selector-matching time. The rest of the checks aren't based on whether the element is a link, or are properly guarded by parent_style.visited_style().is_some() or visited_rules.is_some(). Thus you can transitively infer that no element will end up with a :visited style, not even from style reparenting. Anyway, the underlying reason why I want the element in StyleAdjuster is because we're going to implement an adjustment in there depending on the tag of the element (converting display: contents to display: none depending on the tag), so computing that information eagerly, including a hash lookup, wouldn't be nice. --- components/script_layout_interface/wrapper_traits.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'components/script_layout_interface') diff --git a/components/script_layout_interface/wrapper_traits.rs b/components/script_layout_interface/wrapper_traits.rs index ffdc9aa95ed..0b04d4256a6 100644 --- a/components/script_layout_interface/wrapper_traits.rs +++ b/components/script_layout_interface/wrapper_traits.rs @@ -22,7 +22,7 @@ use style::data::ElementData; use style::dom::{LayoutIterator, NodeInfo, TElement, TNode}; use style::dom::OpaqueNode; use style::font_metrics::ServoMetricsProvider; -use style::properties::{CascadeFlags, ComputedValues}; +use style::properties::ComputedValues; use style::selector_parser::{PseudoElement, PseudoElementCascadeType, SelectorImpl}; use style::stylist::RuleInclusion; use webrender_api::ClipId; @@ -393,7 +393,6 @@ pub trait ThreadSafeLayoutElement &context.guards, &style_pseudo, Some(data.styles.primary()), - CascadeFlags::empty(), &ServoMetricsProvider, ) } -- cgit v1.2.3