diff options
author | Dan Fox <iamdanfox@gmail.com> | 2015-03-03 17:49:10 +0000 |
---|---|---|
committer | Dan Fox <iamdanfox@gmail.com> | 2015-03-03 17:49:10 +0000 |
commit | b424de2092b818c9ed76679ffcd6ecfa621e62ef (patch) | |
tree | 04f83b0d3fcbefdaa8fe079723e4cd10251ee36f /components | |
parent | 417a932e306438b5cda7a7071412a34d3e503f94 (diff) | |
download | servo-b424de2092b818c9ed76679ffcd6ecfa621e62ef.tar.gz servo-b424de2092b818c9ed76679ffcd6ecfa621e62ef.zip |
Extract OpaqueNodeMethods to own file
Diffstat (limited to 'components')
-rw-r--r-- | components/layout/construct.rs | 3 | ||||
-rw-r--r-- | components/layout/display_list_builder.rs | 3 | ||||
-rw-r--r-- | components/layout/fragment.rs | 2 | ||||
-rw-r--r-- | components/layout/layout_task.rs | 3 | ||||
-rw-r--r-- | components/layout/lib.rs | 1 | ||||
-rw-r--r-- | components/layout/opaque_node.rs | 63 | ||||
-rw-r--r-- | components/layout/util.rs | 60 | ||||
-rw-r--r-- | components/layout/wrapper.rs | 3 |
8 files changed, 76 insertions, 62 deletions
diff --git a/components/layout/construct.rs b/components/layout/construct.rs index b2ea8090ea6..5b691cef5cc 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -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; diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index 039dbc9c376..7c56c574581 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -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; diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 26a91139b31..ed6e3920f88 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -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; diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index ca321f23526..6e7886cbecb 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -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; diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 837945eff81..e34704b5039 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -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; diff --git a/components/layout/opaque_node.rs b/components/layout/opaque_node.rs new file mode 100644 index 00000000000..e40538251de --- /dev/null +++ b/components/layout/opaque_node.rs @@ -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) + } +} diff --git a/components/layout/util.rs b/components/layout/util.rs index 8d4d72e7466..85c0e1a60d9 100644 --- a/components/layout/util.rs +++ b/components/layout/util.rs @@ -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. diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 54f341d1d09..87216585d04 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -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; |