Skip to content

Commit

Permalink
Simplify code for directionality
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Feb 24, 2020
1 parent edb940e commit 35d340d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
13 changes: 5 additions & 8 deletions components/script/dom/element.rs
Expand Up @@ -543,15 +543,12 @@ impl Element {

// https://html.spec.whatwg.org/multipage/#the-directionality
pub fn directionality(&self) -> String {
if let Some(directionality) = self
.downcast::<HTMLElement>()
self.downcast::<HTMLElement>()
.and_then(|html_element| html_element.directionality())
{
directionality
} else {
let node = self.upcast::<Node>();
node.parent_directionality()
}
.unwrap_or_else(|| {
let node = self.upcast::<Node>();
node.parent_directionality()
})
}
}

Expand Down
10 changes: 4 additions & 6 deletions components/script/dom/node.rs
Expand Up @@ -438,21 +438,19 @@ impl Node {

loop {
match current {
Some(parent) => {
if let Some(directionality) = parent
Some(node) => {
if let Some(directionality) = node
.downcast::<HTMLElement>()
.and_then(|html_element| html_element.directionality())
{
return directionality;
} else {
current = parent.GetParentNode();
current = node.GetParentNode();
}
},
None => break,
None => return "ltr".to_owned(),
}
}

"ltr".to_owned()
}
}

Expand Down

0 comments on commit 35d340d

Please sign in to comment.