mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Move around some code in the element
The intent is to merge the two layout helper traits together so I'm moving them around to make later diffs more readable.
This commit is contained in:
parent
fb1ff3f097
commit
3b504148d5
1 changed files with 52 additions and 52 deletions
|
@ -550,21 +550,6 @@ impl Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
pub trait RawLayoutElementHelpers {
|
|
||||||
unsafe fn get_attr_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a AttrValue>;
|
|
||||||
unsafe fn get_attr_val_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a str>;
|
|
||||||
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a AttrValue>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub unsafe fn get_attr_for_layout<'dom>(
|
pub unsafe fn get_attr_for_layout<'dom>(
|
||||||
|
@ -583,43 +568,6 @@ pub unsafe fn get_attr_for_layout<'dom>(
|
||||||
.map(|attr| attr.to_layout())
|
.map(|attr| attr.to_layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
impl RawLayoutElementHelpers for Element {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn get_attr_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a AttrValue> {
|
|
||||||
get_attr_for_layout(self, namespace, name).map(|attr| attr.value())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
unsafe fn get_attr_val_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a str> {
|
|
||||||
get_attr_for_layout(self, namespace, name).map(|attr| attr.as_str())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a AttrValue> {
|
|
||||||
let attrs = self.attrs.borrow_for_layout();
|
|
||||||
attrs
|
|
||||||
.iter()
|
|
||||||
.filter_map(|attr| {
|
|
||||||
let attr = attr.to_layout();
|
|
||||||
if name == attr.local_name() {
|
|
||||||
Some(attr.value())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait LayoutElementHelpers<'dom> {
|
pub trait LayoutElementHelpers<'dom> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
|
unsafe fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
|
||||||
|
@ -649,6 +597,21 @@ pub trait LayoutElementHelpers<'dom> {
|
||||||
unsafe fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
unsafe fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
pub trait RawLayoutElementHelpers {
|
||||||
|
unsafe fn get_attr_for_layout<'a>(
|
||||||
|
&'a self,
|
||||||
|
namespace: &Namespace,
|
||||||
|
name: &LocalName,
|
||||||
|
) -> Option<&'a AttrValue>;
|
||||||
|
unsafe fn get_attr_val_for_layout<'a>(
|
||||||
|
&'a self,
|
||||||
|
namespace: &Namespace,
|
||||||
|
name: &LocalName,
|
||||||
|
) -> Option<&'a str>;
|
||||||
|
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a AttrValue>;
|
||||||
|
}
|
||||||
|
|
||||||
impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1105,6 +1068,43 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
impl RawLayoutElementHelpers for Element {
|
||||||
|
#[inline]
|
||||||
|
unsafe fn get_attr_for_layout<'a>(
|
||||||
|
&'a self,
|
||||||
|
namespace: &Namespace,
|
||||||
|
name: &LocalName,
|
||||||
|
) -> Option<&'a AttrValue> {
|
||||||
|
get_attr_for_layout(self, namespace, name).map(|attr| attr.value())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
unsafe fn get_attr_val_for_layout<'a>(
|
||||||
|
&'a self,
|
||||||
|
namespace: &Namespace,
|
||||||
|
name: &LocalName,
|
||||||
|
) -> Option<&'a str> {
|
||||||
|
get_attr_for_layout(self, namespace, name).map(|attr| attr.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a AttrValue> {
|
||||||
|
let attrs = self.attrs.borrow_for_layout();
|
||||||
|
attrs
|
||||||
|
.iter()
|
||||||
|
.filter_map(|attr| {
|
||||||
|
let attr = attr.to_layout();
|
||||||
|
if name == attr.local_name() {
|
||||||
|
Some(attr.value())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
pub fn is_html_element(&self) -> bool {
|
pub fn is_html_element(&self) -> bool {
|
||||||
self.namespace == ns!(html)
|
self.namespace == ns!(html)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue