mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
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 <E>, 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.
This commit is contained in:
parent
6f543d3de1
commit
5ac12b5df4
10 changed files with 425 additions and 207 deletions
|
@ -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<ConcreteNode> Iterator for TreeIterator<ConcreteNode>
|
|||
/// 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<ConcreteThreadSafeLayoutNode = Self>;
|
||||
type ConcreteElement: TElement = <Self::ConcreteNode as TNode>::ConcreteElement;
|
||||
|
||||
type ConcreteThreadSafeLayoutElement:
|
||||
ThreadSafeLayoutElement<ConcreteThreadSafeLayoutNode = Self>
|
||||
+ ::selectors::Element<Impl=SelectorImpl>;
|
||||
|
@ -291,6 +293,10 @@ pub trait ThreadSafeLayoutElement
|
|||
{
|
||||
type ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<ConcreteThreadSafeLayoutElement = Self>;
|
||||
|
||||
/// This type alias is just a hack to avoid writing the monstrosity after it
|
||||
/// twice.
|
||||
type ConcreteElement: TElement = <Self::ConcreteThreadSafeLayoutNode as ThreadSafeLayoutNode>::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) ->
|
||||
<<Self::ConcreteThreadSafeLayoutNode as ThreadSafeLayoutNode>::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::<Self::ConcreteElement>(
|
||||
&context.guards,
|
||||
&style_pseudo,
|
||||
Some(data.styles.primary()),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue