Fix JS roots assertion when clicking on an element

This commit is contained in:
Glenn Watson 2014-05-06 12:01:54 +10:00
parent b14b2eca37
commit 87e6921d46

View file

@ -1100,25 +1100,19 @@ impl ScriptTask {
match page.hit_test(&point) { match page.hit_test(&point) {
Some(node_address) => { Some(node_address) => {
debug!("node address is {:?}", node_address); debug!("node address is {:?}", node_address);
let mut node =
node::from_untrusted_node_address(self.js_runtime.deref().ptr,
node_address).root();
debug!("clicked on {:s}", node.deref().debug_str());
// Traverse node generations until a node that is an element is let temp_node =
// found. node::from_untrusted_node_address(
while !node.deref().is_element() { self.js_runtime.deref().ptr, node_address);
match node.deref().parent_node() {
Some(parent) => node = parent.root(),
None => break,
}
}
if node.deref().is_element() { let maybe_node = temp_node.root().ancestors().find(|node| node.is_anchor_element());
let element: &JSRef<Element> = ElementCast::to_ref(&*node).unwrap(); match maybe_node {
if "a" == element.deref().local_name { Some(node) => {
self.load_url_from_element(page, element) debug!("clicked on {:s}", node.debug_str());
let element: &JSRef<Element> = ElementCast::to_ref(&node).unwrap();
self.load_url_from_element(page, element);
} }
None => {}
} }
} }