Add a 'dom lifetime to GetLayoutData

This commit is contained in:
Anthony Ramine 2020-03-26 13:17:46 +01:00
parent 2d055cbf6b
commit 04af32128c
15 changed files with 130 additions and 125 deletions

View file

@ -181,12 +181,15 @@ pub struct InlineBlockSplit {
impl InlineBlockSplit {
/// Flushes the given accumulator to the new split and makes a new accumulator to hold any
/// subsequent fragments.
fn new<ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>(
fn new<'dom, ConcreteThreadSafeLayoutNode>(
fragment_accumulator: &mut InlineFragmentsAccumulator,
node: &ConcreteThreadSafeLayoutNode,
style_context: &SharedStyleContext,
flow: FlowRef,
) -> InlineBlockSplit {
) -> InlineBlockSplit
where
ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'dom>,
{
fragment_accumulator.enclosing_node.as_mut().expect(
"enclosing_node is None; Are {ib} splits being generated outside of an inline node?"
).flags.remove(InlineFragmentNodeFlags::LAST_FRAGMENT_OF_ELEMENT);
@ -272,13 +275,10 @@ impl InlineFragmentsAccumulator {
}
}
fn from_inline_node<N>(
node: &N,
fn from_inline_node<'dom>(
node: &impl ThreadSafeLayoutNode<'dom>,
style_context: &SharedStyleContext,
) -> InlineFragmentsAccumulator
where
N: ThreadSafeLayoutNode,
{
) -> InlineFragmentsAccumulator {
InlineFragmentsAccumulator {
fragments: IntermediateInlineFragments::new(),
enclosing_node: Some(InlineFragmentNodeInfo {
@ -305,12 +305,12 @@ impl InlineFragmentsAccumulator {
.push_descendants(fragments.absolute_descendants);
}
fn to_intermediate_inline_fragments<N>(
fn to_intermediate_inline_fragments<'dom, N>(
self,
context: &SharedStyleContext,
) -> IntermediateInlineFragments
where
N: ThreadSafeLayoutNode,
N: ThreadSafeLayoutNode<'dom>,
{
let InlineFragmentsAccumulator {
mut fragments,
@ -366,7 +366,7 @@ impl InlineFragmentsAccumulator {
}
/// An object that knows how to create flows.
pub struct FlowConstructor<'a, N: ThreadSafeLayoutNode> {
pub struct FlowConstructor<'a, N> {
/// The layout context.
pub layout_context: &'a LayoutContext<'a>,
/// Satisfy the compiler about the unused parameters, which we use to improve the ergonomics of
@ -374,8 +374,9 @@ pub struct FlowConstructor<'a, N: ThreadSafeLayoutNode> {
phantom2: PhantomData<N>,
}
impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
FlowConstructor<'a, ConcreteThreadSafeLayoutNode>
impl<'a, 'dom, ConcreteThreadSafeLayoutNode> FlowConstructor<'a, ConcreteThreadSafeLayoutNode>
where
ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'dom>,
{
/// Creates a new flow constructor.
pub fn new(layout_context: &'a LayoutContext<'a>) -> Self {
@ -1792,10 +1793,11 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
}
}
impl<'a, ConcreteThreadSafeLayoutNode> PostorderNodeMutTraversal<ConcreteThreadSafeLayoutNode>
impl<'a, 'dom, ConcreteThreadSafeLayoutNode>
PostorderNodeMutTraversal<'dom, ConcreteThreadSafeLayoutNode>
for FlowConstructor<'a, ConcreteThreadSafeLayoutNode>
where
ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode,
ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'dom>,
{
// Construct Flow based on 'display', 'position', and 'float' values.
//
@ -1988,9 +1990,9 @@ trait NodeUtils {
fn get_construction_result(self) -> ConstructionResult;
}
impl<ConcreteThreadSafeLayoutNode> NodeUtils for ConcreteThreadSafeLayoutNode
impl<'dom, ConcreteThreadSafeLayoutNode> NodeUtils for ConcreteThreadSafeLayoutNode
where
ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode,
ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'dom>,
{
fn is_replaced_content(&self) -> bool {
match self.type_id() {

View file

@ -411,10 +411,10 @@ impl ImageFragmentInfo {
///
/// FIXME(pcwalton): The fact that image fragments store the cache in the fragment makes little
/// sense to me.
pub fn new<N: ThreadSafeLayoutNode>(
pub fn new<'dom>(
url: Option<ServoUrl>,
density: Option<f64>,
node: &N,
node: &impl ThreadSafeLayoutNode<'dom>,
layout_context: &LayoutContext,
) -> ImageFragmentInfo {
// First use any image data present in the element...
@ -488,7 +488,7 @@ pub struct IframeFragmentInfo {
impl IframeFragmentInfo {
/// Creates the information specific to an iframe fragment.
pub fn new<N: ThreadSafeLayoutNode>(node: &N) -> IframeFragmentInfo {
pub fn new<'dom>(node: &impl ThreadSafeLayoutNode<'dom>) -> IframeFragmentInfo {
let browsing_context_id = node.iframe_browsing_context_id();
let pipeline_id = node.iframe_pipeline_id();
IframeFragmentInfo {
@ -642,7 +642,7 @@ pub struct TableColumnFragmentInfo {
impl TableColumnFragmentInfo {
/// Create the information specific to an table column fragment.
pub fn new<N: ThreadSafeLayoutNode>(node: &N) -> TableColumnFragmentInfo {
pub fn new<'dom>(node: &impl ThreadSafeLayoutNode<'dom>) -> TableColumnFragmentInfo {
let element = node.as_element().unwrap();
let span = element
.get_attr(&ns!(), &local_name!("span"))
@ -663,8 +663,8 @@ pub struct TruncatedFragmentInfo {
impl Fragment {
/// Constructs a new `Fragment` instance.
pub fn new<N: ThreadSafeLayoutNode>(
node: &N,
pub fn new<'dom>(
node: &impl ThreadSafeLayoutNode<'dom>,
specific: SpecificFragmentInfo,
ctx: &LayoutContext,
) -> Fragment {

View file

@ -688,9 +688,9 @@ pub fn process_client_rect_query(
iterator.client_rect
}
pub fn process_node_scroll_id_request<N: LayoutNode>(
pub fn process_node_scroll_id_request<'dom>(
id: PipelineId,
requested_node: N,
requested_node: impl LayoutNode<'dom>,
) -> ExternalScrollId {
let layout_node = requested_node.to_threadsafe();
layout_node.generate_scroll_id(id)
@ -747,16 +747,13 @@ pub fn process_node_scroll_area_request(
/// Return the resolved value of property for a given (pseudo)element.
/// <https://drafts.csswg.org/cssom/#resolved-value>
pub fn process_resolved_style_request<'a, N>(
pub fn process_resolved_style_request<'dom>(
context: &LayoutContext,
node: N,
node: impl LayoutNode<'dom>,
pseudo: &Option<PseudoElement>,
property: &PropertyId,
layout_root: &mut dyn Flow,
) -> String
where
N: LayoutNode,
{
) -> String {
use style::stylist::RuleInclusion;
use style::traversal::resolve_style;
@ -797,15 +794,12 @@ where
}
/// The primary resolution logic, which assumes that the element is styled.
fn process_resolved_style_request_internal<'a, N>(
requested_node: N,
fn process_resolved_style_request_internal<'dom>(
requested_node: impl LayoutNode<'dom>,
pseudo: &Option<PseudoElement>,
property: &PropertyId,
layout_root: &mut dyn Flow,
) -> String
where
N: LayoutNode,
{
) -> String {
let layout_el = requested_node.to_threadsafe().as_element().unwrap();
let layout_el = match *pseudo {
Some(PseudoElement::Before) => layout_el.get_before_pseudo(),
@ -851,12 +845,15 @@ where
// There are probably other quirks.
let applies = true;
fn used_value_for_position_property<N: LayoutNode>(
layout_el: <N::ConcreteThreadSafeLayoutNode as ThreadSafeLayoutNode>::ConcreteThreadSafeLayoutElement,
fn used_value_for_position_property<'dom, N>(
layout_el: <N::ConcreteThreadSafeLayoutNode as ThreadSafeLayoutNode<'dom>>::ConcreteThreadSafeLayoutElement,
layout_root: &mut dyn Flow,
requested_node: N,
longhand_id: LonghandId,
) -> String {
) -> String
where
N: LayoutNode<'dom>,
{
let maybe_data = layout_el.borrow_layout_data();
let position = maybe_data.map_or(Point2D::zero(), |data| {
match (*data).flow_construction_result {
@ -969,7 +966,7 @@ pub fn process_offset_parent_query(
}
}
pub fn process_style_query<N: LayoutNode>(requested_node: N) -> StyleResponse {
pub fn process_style_query<'dom>(requested_node: impl LayoutNode<'dom>) -> StyleResponse {
let element = requested_node.as_element().unwrap();
let data = element.borrow_data();
@ -982,8 +979,8 @@ enum InnerTextItem {
}
// https://html.spec.whatwg.org/multipage/#the-innertext-idl-attribute
pub fn process_element_inner_text_query<N: LayoutNode>(
node: N,
pub fn process_element_inner_text_query<'dom>(
node: impl LayoutNode<'dom>,
indexable_text: &IndexableText,
) -> String {
// Step 1.
@ -1027,8 +1024,8 @@ pub fn process_element_inner_text_query<N: LayoutNode>(
// https://html.spec.whatwg.org/multipage/#inner-text-collection-steps
#[allow(unsafe_code)]
fn inner_text_collection_steps<N: LayoutNode>(
node: N,
fn inner_text_collection_steps<'dom>(
node: impl LayoutNode<'dom>,
indexable_text: &IndexableText,
results: &mut Vec<InnerTextItem>,
) {

View file

@ -61,8 +61,8 @@ impl TableCellFlow {
}
}
pub fn from_node_fragment_and_visibility_flag<N: ThreadSafeLayoutNode>(
node: &N,
pub fn from_node_fragment_and_visibility_flag<'dom>(
node: &impl ThreadSafeLayoutNode<'dom>,
fragment: Fragment,
visible: bool,
) -> TableCellFlow {

View file

@ -38,10 +38,10 @@ impl<'a> RecalcStyleAndConstructFlows<'a> {
}
#[allow(unsafe_code)]
impl<'a, E> DomTraversal<E> for RecalcStyleAndConstructFlows<'a>
impl<'a, 'dom, E> DomTraversal<E> for RecalcStyleAndConstructFlows<'a>
where
E: TElement,
E::ConcreteNode: LayoutNode,
E::ConcreteNode: LayoutNode<'dom>,
E::FontMetricsProvider: Send,
{
fn process_preorder<F>(
@ -175,7 +175,10 @@ pub trait InorderFlowTraversal {
}
/// A bottom-up, parallelizable traversal.
pub trait PostorderNodeMutTraversal<ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode> {
pub trait PostorderNodeMutTraversal<'dom, ConcreteThreadSafeLayoutNode>
where
ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode<'dom>,
{
/// The operation to perform. Return true to continue or false to stop.
fn process(&mut self, node: &ConcreteThreadSafeLayoutNode);
}
@ -183,10 +186,7 @@ pub trait PostorderNodeMutTraversal<ConcreteThreadSafeLayoutNode: ThreadSafeLayo
/// The flow construction traversal, which builds flows for styled nodes.
#[inline]
#[allow(unsafe_code)]
fn construct_flows_at<N>(context: &LayoutContext, node: N)
where
N: LayoutNode,
{
fn construct_flows_at<'dom>(context: &LayoutContext, node: impl LayoutNode<'dom>) {
debug!("construct_flows_at: {:?}", node);
// Construct flows for this node.

View file

@ -47,7 +47,10 @@ pub trait LayoutNodeLayoutData {
fn flow_debug_id(self) -> usize;
}
impl<T: GetLayoutData> LayoutNodeLayoutData for T {
impl<'dom, T> LayoutNodeLayoutData for T
where
T: GetLayoutData<'dom>,
{
fn borrow_layout_data(&self) -> Option<AtomicRef<LayoutData>> {
self.get_raw_data().map(|d| d.layout_data.borrow())
}
@ -66,7 +69,10 @@ pub trait GetRawData {
fn get_raw_data(&self) -> Option<&StyleAndLayoutData>;
}
impl<T: GetLayoutData> GetRawData for T {
impl<'dom, T> GetRawData for T
where
T: GetLayoutData<'dom>,
{
fn get_raw_data(&self) -> Option<&StyleAndLayoutData> {
self.get_style_and_layout_data().map(|opaque| {
let container = opaque.ptr.as_ptr() as *mut StyleAndLayoutData;
@ -98,7 +104,10 @@ pub trait ThreadSafeLayoutNodeHelpers {
fn restyle_damage(self) -> RestyleDamage;
}
impl<T: ThreadSafeLayoutNode> ThreadSafeLayoutNodeHelpers for T {
impl<'dom, T> ThreadSafeLayoutNodeHelpers for T
where
T: ThreadSafeLayoutNode<'dom>,
{
fn flags(self) -> LayoutDataFlags {
self.borrow_layout_data().as_ref().unwrap().flags
}