layout_api/
layout_dom.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5#![deny(missing_docs)]
6
7use crate::{DangerousStyleElement, DangerousStyleNode, LayoutElement, LayoutNode};
8
9/// A trait that holds all the concrete implementations of the Layout DOM traits. This is
10/// useful because it means that other types (specifically the implementation of the `Layout`
11/// trait) can be parameterized over a single type (`LayoutDomTypeBundle`) rather than all of
12/// the various Layout DOM trait implementations.
13pub trait LayoutDomTypeBundle<'dom> {
14    /// The concrete implementation of [`LayoutNode`] from `script`.
15    type ConcreteLayoutNode: LayoutNode<'dom>;
16    /// The concrete implementation of [`LayoutElement`] from `script`.
17    type ConcreteLayoutElement: LayoutElement<'dom>;
18    /// The concrete implementation of [`DangerousStyleNode`] from `script`.
19    type ConcreteDangerousStyleNode: DangerousStyleNode<'dom>;
20    /// The concrete implementation of [`DangerousStyleElement`] from `script`.
21    type ConcreteDangerousStyleElement: DangerousStyleElement<'dom>;
22}
23
24// The type aliases below simplify extracting the concrete types out of the type bundle. It will be
25// possible to simplify this once default associated types have landed and are stable:
26// https://github.com/rust-lang/rust/issues/29661.
27
28/// Type alias to extract `ConcreteLayoutNode` from a `LayoutDomTypeBundle` implementation.
29pub type LayoutNodeOf<'dom, T> = <T as LayoutDomTypeBundle<'dom>>::ConcreteLayoutNode;
30
31/// Type alias to extract `ConcreteLayoutElement` from a `LayoutDomTypeBundle` implementation.
32pub type LayoutElementOf<'dom, T> = <T as LayoutDomTypeBundle<'dom>>::ConcreteLayoutElement;
33
34/// Type alias to extract `ConcreteDangerousStyleNode` from a `LayoutDomTypeBundle` implementation.
35pub type DangerousStyleNodeOf<'dom, T> =
36    <T as LayoutDomTypeBundle<'dom>>::ConcreteDangerousStyleNode;
37
38/// Type alias to extract `ConcreteDangerousStyleElement` from a `LayoutDomTypeBundle` implementation.
39pub type DangerousStyleElementOf<'dom, T> =
40    <T as LayoutDomTypeBundle<'dom>>::ConcreteDangerousStyleElement;