Make LayoutNodeHelpers::composed_parent_node_ref be safe

For clarity, I introduce <LayoutDom<Element>>::parent_node_ref to contain
the remaining unsafety bits out of composed_parent_node_ref which is more
complex than just a field access.
This commit is contained in:
Anthony Ramine 2020-03-31 22:32:35 +02:00
parent f712b0bcf8
commit fc07a5147c
4 changed files with 44 additions and 50 deletions

View file

@ -985,32 +985,27 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
unsafe { &(*self.unsafe_get()).namespace }
}
#[allow(unsafe_code)]
fn get_lang_for_layout(self) -> String {
unsafe {
let mut current_node = Some(self.upcast::<Node>());
while let Some(node) = current_node {
current_node = node.composed_parent_node_ref();
match node.downcast::<Element>() {
Some(elem) => {
if let Some(attr) =
elem.get_attr_val_for_layout(&ns!(xml), &local_name!("lang"))
{
return attr.to_owned();
}
if let Some(attr) =
elem.get_attr_val_for_layout(&ns!(), &local_name!("lang"))
{
return attr.to_owned();
}
},
None => continue,
}
let mut current_node = Some(self.upcast::<Node>());
while let Some(node) = current_node {
current_node = node.composed_parent_node_ref();
match node.downcast::<Element>() {
Some(elem) => {
if let Some(attr) =
elem.get_attr_val_for_layout(&ns!(xml), &local_name!("lang"))
{
return attr.to_owned();
}
if let Some(attr) = elem.get_attr_val_for_layout(&ns!(), &local_name!("lang")) {
return attr.to_owned();
}
},
None => continue,
}
// TODO: Check meta tags for a pragma-set default language
// TODO: Check HTTP Content-Language header
String::new()
}
// TODO: Check meta tags for a pragma-set default language
// TODO: Check HTTP Content-Language header
String::new()
}
#[inline]