Introduce LayoutDom::is

Just like Castable::is.
This commit is contained in:
Anthony Ramine 2020-03-31 22:06:26 +02:00
parent 9c8540af5c
commit f014da9565
4 changed files with 14 additions and 6 deletions

View file

@ -141,7 +141,7 @@ impl<'ln> ServoLayoutNode<'ln> {
impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
fn is_element(&self) -> bool {
unsafe { self.node.is_element_for_layout() }
self.node.is_element_for_layout()
}
fn is_text_node(&self) -> bool {

View file

@ -148,7 +148,7 @@ impl<'ln> ServoLayoutNode<'ln> {
impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
fn is_element(&self) -> bool {
unsafe { self.node.is_element_for_layout() }
self.node.is_element_for_layout()
}
fn is_text_node(&self) -> bool {

View file

@ -441,6 +441,15 @@ where
debug_assert!(thread_state::get().is_layout());
self.value.downcast::<U>().map(|value| LayoutDom { value })
}
/// Returns whether this inner object is a U.
pub fn is<U>(&self) -> bool
where
U: DerivedFrom<T>,
{
debug_assert!(thread_state::get().is_layout());
self.value.is::<U>()
}
}
impl<T> LayoutDom<'_, T>

View file

@ -1316,7 +1316,7 @@ pub trait LayoutNodeHelpers<'dom> {
unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>;
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
unsafe fn is_element_for_layout(self) -> bool;
fn is_element_for_layout(self) -> bool;
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
unsafe fn set_flag(self, flag: NodeFlags, value: bool);
@ -1347,9 +1347,8 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
}
#[inline]
#[allow(unsafe_code)]
unsafe fn is_element_for_layout(self) -> bool {
(*self.unsafe_get()).is::<Element>()
fn is_element_for_layout(self) -> bool {
self.is::<Element>()
}
#[inline]