Remove recursiveness from directionality search

This commit is contained in:
Dmitry Kolupaev 2020-02-16 19:14:40 +03:00
parent 7e2107b1a5
commit edb940e613
4 changed files with 35 additions and 26 deletions

View file

@ -774,17 +774,17 @@ impl HTMLElement {
.count() as u32
}
pub fn directionality(&self) -> String {
println!("HTMLElement#directionality");
// returns Some if can infer direction by itself or from child nodes
// returns None if requires to go up to parent
pub fn directionality(&self) -> Option<String> {
let element_direction: &str = &self.Dir();
println!("HTMLElement#element_direction={}", element_direction);
if element_direction == "ltr" {
return "ltr".to_owned();
return Some("ltr".to_owned());
}
if element_direction == "rtl" {
return "rtl".to_owned();
return Some("rtl".to_owned());
}
if element_direction == "auto" {
@ -792,11 +792,11 @@ impl HTMLElement {
.downcast::<HTMLInputElement>()
.and_then(|input| input.auto_directionality())
{
return directionality;
return Some(directionality);
}
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
return area.auto_directionality();
return Some(area.auto_directionality());
}
}
@ -806,8 +806,7 @@ impl HTMLElement {
// (i.e. it is not present or has an invalid value)
// Requires bdi element implementation (https://html.spec.whatwg.org/multipage/#the-bdi-element)
let node = self.upcast::<Node>();
node.parent_directionality()
None
}
}