Introduce LayoutJS<Node>::opaque() to replace OpaqueNodeMethods::from_jsmanaged().

This commit is contained in:
Ms2ger 2016-06-15 17:10:46 +01:00
parent 14a7e9bce1
commit 7de3d165ad
3 changed files with 12 additions and 17 deletions

View file

@ -2,31 +2,17 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#![allow(unsafe_code)]
use gfx::display_list::OpaqueNode;
use libc::{c_void, uintptr_t};
use script::layout_interface::LayoutJS;
use script::layout_interface::Node;
use libc::c_void;
use script_traits::UntrustedNodeAddress;
pub trait OpaqueNodeMethods {
/// Converts a DOM node to an `OpaqueNode'.
fn from_jsmanaged(node: &LayoutJS<Node>) -> Self;
/// Converts this node to an `UntrustedNodeAddress`. An `UntrustedNodeAddress` is just the type
/// of node that script expects to receive in a hit test.
fn to_untrusted_node_address(&self) -> UntrustedNodeAddress;
}
impl OpaqueNodeMethods for OpaqueNode {
fn from_jsmanaged(node: &LayoutJS<Node>) -> OpaqueNode {
unsafe {
let ptr: uintptr_t = node.get_jsobject() as uintptr_t;
OpaqueNode(ptr)
}
}
fn to_untrusted_node_address(&self) -> UntrustedNodeAddress {
UntrustedNodeAddress(self.0 as *const c_void)
}

View file

@ -156,7 +156,7 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
}
fn opaque(&self) -> OpaqueNode {
OpaqueNodeMethods::from_jsmanaged(unsafe { self.get_jsmanaged() })
unsafe { self.get_jsmanaged().opaque() }
}
fn layout_parent_node(self, reflow_root: OpaqueNode) -> Option<ServoLayoutNode<'ln>> {
@ -732,7 +732,7 @@ impl<'ln> ThreadSafeLayoutNode for ServoThreadSafeLayoutNode<'ln> {
}
fn opaque(&self) -> OpaqueNode {
OpaqueNodeMethods::from_jsmanaged(unsafe { self.get_jsmanaged() })
unsafe { self.get_jsmanaged().opaque() }
}
fn type_id(&self) -> Option<LayoutNodeType> {

View file

@ -75,6 +75,7 @@ use std::iter::{self, FilterMap, Peekable};
use std::mem;
use std::ops::Range;
use string_cache::{Atom, Namespace, QualName};
use style::dom::OpaqueNode;
use style::selector_impl::ServoSelectorImpl;
use url::Url;
use util::thread_state;
@ -961,6 +962,7 @@ pub trait LayoutNodeHelpers {
fn image_url(&self) -> Option<Url>;
fn canvas_data(&self) -> Option<HTMLCanvasData>;
fn iframe_pipeline_id(&self) -> PipelineId;
fn opaque(&self) -> OpaqueNode;
}
impl LayoutNodeHelpers for LayoutJS<Node> {
@ -1101,6 +1103,13 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
.expect("not an iframe element!");
iframe_element.pipeline_id().unwrap()
}
#[allow(unsafe_code)]
fn opaque(&self) -> OpaqueNode {
unsafe {
OpaqueNode(self.get_jsobject() as usize)
}
}
}