mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Simplify code for directionality
This commit is contained in:
parent
edb940e613
commit
35d340daba
2 changed files with 9 additions and 14 deletions
|
@ -543,15 +543,12 @@ impl Element {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#the-directionality
|
// https://html.spec.whatwg.org/multipage/#the-directionality
|
||||||
pub fn directionality(&self) -> String {
|
pub fn directionality(&self) -> String {
|
||||||
if let Some(directionality) = self
|
self.downcast::<HTMLElement>()
|
||||||
.downcast::<HTMLElement>()
|
|
||||||
.and_then(|html_element| html_element.directionality())
|
.and_then(|html_element| html_element.directionality())
|
||||||
{
|
.unwrap_or_else(|| {
|
||||||
directionality
|
let node = self.upcast::<Node>();
|
||||||
} else {
|
node.parent_directionality()
|
||||||
let node = self.upcast::<Node>();
|
})
|
||||||
node.parent_directionality()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -438,21 +438,19 @@ impl Node {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match current {
|
match current {
|
||||||
Some(parent) => {
|
Some(node) => {
|
||||||
if let Some(directionality) = parent
|
if let Some(directionality) = node
|
||||||
.downcast::<HTMLElement>()
|
.downcast::<HTMLElement>()
|
||||||
.and_then(|html_element| html_element.directionality())
|
.and_then(|html_element| html_element.directionality())
|
||||||
{
|
{
|
||||||
return directionality;
|
return directionality;
|
||||||
} else {
|
} else {
|
||||||
current = parent.GetParentNode();
|
current = node.GetParentNode();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => break,
|
None => return "ltr".to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"ltr".to_owned()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue