diff options
Diffstat (limited to 'src/components/main/layout/util.rs')
-rw-r--r-- | src/components/main/layout/util.rs | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/components/main/layout/util.rs b/src/components/main/layout/util.rs index 65cf0b6b676..8ef031bfb3f 100644 --- a/src/components/main/layout/util.rs +++ b/src/components/main/layout/util.rs @@ -7,8 +7,9 @@ use layout::construct::{ConstructionResult, NoConstructionResult}; use layout::wrapper::LayoutNode; use extra::arc::Arc; +use script::dom::bindings::utils::Reflectable; use script::dom::node::AbstractNode; -use script::layout_interface::LayoutChan; +use script::layout_interface::{LayoutChan, UntrustedNodeAddress}; use servo_util::range::Range; use std::cast; use std::cell::{Ref, RefMut}; @@ -211,21 +212,28 @@ impl OpaqueNode { /// Converts a DOM node (layout view) to an `OpaqueNode`. pub fn from_layout_node(node: &LayoutNode) -> OpaqueNode { unsafe { - OpaqueNode(cast::transmute_copy(node)) + let abstract_node = node.get_abstract(); + let ptr: uintptr_t = cast::transmute(abstract_node.reflector().get_jsobject()); + OpaqueNode(ptr) } } /// Converts a DOM node (script view) to an `OpaqueNode`. pub fn from_script_node(node: &AbstractNode) -> OpaqueNode { unsafe { - OpaqueNode(cast::transmute_copy(node)) + let ptr: uintptr_t = cast::transmute(node.reflector().get_jsobject()); + OpaqueNode(ptr) } } - /// Unsafely converts an `OpaqueNode` to a DOM node (script view). Use this only if you - /// absolutely know what you're doing. - pub unsafe fn to_script_node(&self) -> AbstractNode { - cast::transmute(**self) + /// Converts this node to an `UntrustedNodeAddress`. An `UntrustedNodeAddress` is just the type + /// of node that script expects to receive in a hit test. + pub fn to_untrusted_node_address(&self) -> UntrustedNodeAddress { + unsafe { + let OpaqueNode(addr) = *self; + let addr: UntrustedNodeAddress = cast::transmute(addr); + addr + } } /// Returns the address of this node, for debugging purposes. |