Extract OpaqueNodeMethods to own file

This commit is contained in:
Dan Fox 2015-03-03 17:49:10 +00:00
parent 417a932e30
commit b424de2092
8 changed files with 76 additions and 62 deletions

View file

@ -41,7 +41,8 @@ use table_rowgroup::TableRowGroupFlow;
use table_row::TableRowFlow;
use table_cell::TableCellFlow;
use text::TextRunScanner;
use util::{HAS_NEWLY_CONSTRUCTED_FLOW, LayoutDataAccess, OpaqueNodeMethods, LayoutDataWrapper};
use util::{HAS_NEWLY_CONSTRUCTED_FLOW, LayoutDataAccess, LayoutDataWrapper};
use opaque_node::OpaqueNodeMethods;
use wrapper::{PostorderNodeMutTraversal, PseudoElementType, TLayoutNode, ThreadSafeLayoutNode};
use gfx::display_list::OpaqueNode;

View file

@ -19,7 +19,8 @@ use fragment::{ScannedTextFragmentInfo, SpecificFragmentInfo};
use inline::InlineFlow;
use list_item::ListItemFlow;
use model;
use util::{OpaqueNodeMethods, ToGfxColor};
use util::ToGfxColor;
use opaque_node::OpaqueNodeMethods;
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
use gfx::color;

View file

@ -20,7 +20,7 @@ use layout_debug;
use model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
use model;
use text;
use util::OpaqueNodeMethods;
use opaque_node::OpaqueNodeMethods;
use wrapper::{TLayoutNode, ThreadSafeLayoutNode};
use geom::num::Zero;

View file

@ -17,7 +17,8 @@ use incremental::{LayoutDamageComputation, REFLOW, REFLOW_ENTIRE_DOCUMENT, REPAI
use layout_debug;
use parallel::{self, UnsafeFlow};
use sequential;
use util::{LayoutDataAccess, LayoutDataWrapper, OpaqueNodeMethods, ToGfxColor};
use util::{LayoutDataAccess, LayoutDataWrapper, ToGfxColor};
use opaque_node::OpaqueNodeMethods;
use wrapper::{LayoutNode, TLayoutNode, ThreadSafeLayoutNode};
use encoding::EncodingRef;

View file

@ -70,6 +70,7 @@ pub mod layout_task;
pub mod inline;
pub mod list_item;
pub mod model;
pub mod opaque_node;
pub mod parallel;
pub mod sequential;
pub mod table_wrapper;

View file

@ -0,0 +1,63 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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_blocks)]
use gfx::display_list::OpaqueNode;
use libc::{c_void, uintptr_t};
use script::dom::bindings::js::LayoutJS;
use script::dom::node::Node;
use script::layout_interface::{TrustedNodeAddress};
use script_traits::UntrustedNodeAddress;
use wrapper::{LayoutNode, TLayoutNode, ThreadSafeLayoutNode};
pub trait OpaqueNodeMethods {
/// Converts a DOM node (layout view) to an `OpaqueNode`.
fn from_layout_node(node: &LayoutNode) -> Self;
/// Converts a thread-safe DOM node (layout view) to an `OpaqueNode`.
fn from_thread_safe_layout_node(node: &ThreadSafeLayoutNode) -> Self;
/// Converts a DOM node (script view) to an `OpaqueNode`.
fn from_script_node(node: TrustedNodeAddress) -> Self;
/// 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_layout_node(node: &LayoutNode) -> OpaqueNode {
unsafe {
OpaqueNodeMethods::from_jsmanaged(node.get_jsmanaged())
}
}
fn from_thread_safe_layout_node(node: &ThreadSafeLayoutNode) -> OpaqueNode {
unsafe {
OpaqueNodeMethods::from_jsmanaged(node.get_jsmanaged())
}
}
fn from_script_node(node: TrustedNodeAddress) -> OpaqueNode {
unsafe {
OpaqueNodeMethods::from_jsmanaged(&LayoutJS::from_trusted_node_address(node))
}
}
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 {
let OpaqueNode(addr) = *self;
UntrustedNodeAddress(addr as *const c_void)
}
}

View file

@ -7,16 +7,12 @@
use construct::ConstructionResult;
use incremental::RestyleDamage;
use parallel::DomParallelInfo;
use wrapper::{LayoutNode, TLayoutNode, ThreadSafeLayoutNode};
use wrapper::{LayoutNode, TLayoutNode};
use azure::azure_hl::Color;
use gfx::display_list::OpaqueNode;
use gfx;
use libc::{c_void, uintptr_t};
use script::dom::bindings::js::LayoutJS;
use script::dom::node::{Node, SharedLayoutData};
use script::layout_interface::{LayoutChan, TrustedNodeAddress};
use script_traits::UntrustedNodeAddress;
use script::dom::node::SharedLayoutData;
use script::layout_interface::LayoutChan;
use std::mem;
use std::cell::{Ref, RefMut};
use style::properties::ComputedValues;
@ -123,56 +119,6 @@ impl<'ln> LayoutDataAccess for LayoutNode<'ln> {
}
}
pub trait OpaqueNodeMethods {
/// Converts a DOM node (layout view) to an `OpaqueNode`.
fn from_layout_node(node: &LayoutNode) -> Self;
/// Converts a thread-safe DOM node (layout view) to an `OpaqueNode`.
fn from_thread_safe_layout_node(node: &ThreadSafeLayoutNode) -> Self;
/// Converts a DOM node (script view) to an `OpaqueNode`.
fn from_script_node(node: TrustedNodeAddress) -> Self;
/// 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_layout_node(node: &LayoutNode) -> OpaqueNode {
unsafe {
OpaqueNodeMethods::from_jsmanaged(node.get_jsmanaged())
}
}
fn from_thread_safe_layout_node(node: &ThreadSafeLayoutNode) -> OpaqueNode {
unsafe {
OpaqueNodeMethods::from_jsmanaged(node.get_jsmanaged())
}
}
fn from_script_node(node: TrustedNodeAddress) -> OpaqueNode {
unsafe {
OpaqueNodeMethods::from_jsmanaged(&LayoutJS::from_trusted_node_address(node))
}
}
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 {
let OpaqueNode(addr) = *self;
UntrustedNodeAddress(addr as *const c_void)
}
}
/// Allows a CSS color to be converted into a graphics color.
pub trait ToGfxColor {
/// Converts a CSS color to a graphics color.

View file

@ -36,8 +36,9 @@ use canvas::canvas_paint_task::CanvasMsg;
use context::SharedLayoutContext;
use css::node_style::StyledNode;
use incremental::RestyleDamage;
use util::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper, OpaqueNodeMethods};
use util::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper};
use util::{PrivateLayoutData};
use opaque_node::OpaqueNodeMethods;
use cssparser::RGBA;
use gfx::display_list::OpaqueNode;