mirror of
https://github.com/servo/servo.git
synced 2025-07-28 17:50:37 +01:00
Extract OpaqueNodeMethods to own file
This commit is contained in:
parent
417a932e30
commit
b424de2092
8 changed files with 76 additions and 62 deletions
|
@ -41,7 +41,8 @@ use table_rowgroup::TableRowGroupFlow;
|
||||||
use table_row::TableRowFlow;
|
use table_row::TableRowFlow;
|
||||||
use table_cell::TableCellFlow;
|
use table_cell::TableCellFlow;
|
||||||
use text::TextRunScanner;
|
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 wrapper::{PostorderNodeMutTraversal, PseudoElementType, TLayoutNode, ThreadSafeLayoutNode};
|
||||||
|
|
||||||
use gfx::display_list::OpaqueNode;
|
use gfx::display_list::OpaqueNode;
|
||||||
|
|
|
@ -19,7 +19,8 @@ use fragment::{ScannedTextFragmentInfo, SpecificFragmentInfo};
|
||||||
use inline::InlineFlow;
|
use inline::InlineFlow;
|
||||||
use list_item::ListItemFlow;
|
use list_item::ListItemFlow;
|
||||||
use model;
|
use model;
|
||||||
use util::{OpaqueNodeMethods, ToGfxColor};
|
use util::ToGfxColor;
|
||||||
|
use opaque_node::OpaqueNodeMethods;
|
||||||
|
|
||||||
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
|
use geom::{Point2D, Rect, Size2D, SideOffsets2D};
|
||||||
use gfx::color;
|
use gfx::color;
|
||||||
|
|
|
@ -20,7 +20,7 @@ use layout_debug;
|
||||||
use model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
|
use model::{IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
|
||||||
use model;
|
use model;
|
||||||
use text;
|
use text;
|
||||||
use util::OpaqueNodeMethods;
|
use opaque_node::OpaqueNodeMethods;
|
||||||
use wrapper::{TLayoutNode, ThreadSafeLayoutNode};
|
use wrapper::{TLayoutNode, ThreadSafeLayoutNode};
|
||||||
|
|
||||||
use geom::num::Zero;
|
use geom::num::Zero;
|
||||||
|
|
|
@ -17,7 +17,8 @@ use incremental::{LayoutDamageComputation, REFLOW, REFLOW_ENTIRE_DOCUMENT, REPAI
|
||||||
use layout_debug;
|
use layout_debug;
|
||||||
use parallel::{self, UnsafeFlow};
|
use parallel::{self, UnsafeFlow};
|
||||||
use sequential;
|
use sequential;
|
||||||
use util::{LayoutDataAccess, LayoutDataWrapper, OpaqueNodeMethods, ToGfxColor};
|
use util::{LayoutDataAccess, LayoutDataWrapper, ToGfxColor};
|
||||||
|
use opaque_node::OpaqueNodeMethods;
|
||||||
use wrapper::{LayoutNode, TLayoutNode, ThreadSafeLayoutNode};
|
use wrapper::{LayoutNode, TLayoutNode, ThreadSafeLayoutNode};
|
||||||
|
|
||||||
use encoding::EncodingRef;
|
use encoding::EncodingRef;
|
||||||
|
|
|
@ -70,6 +70,7 @@ pub mod layout_task;
|
||||||
pub mod inline;
|
pub mod inline;
|
||||||
pub mod list_item;
|
pub mod list_item;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
|
pub mod opaque_node;
|
||||||
pub mod parallel;
|
pub mod parallel;
|
||||||
pub mod sequential;
|
pub mod sequential;
|
||||||
pub mod table_wrapper;
|
pub mod table_wrapper;
|
||||||
|
|
63
components/layout/opaque_node.rs
Normal file
63
components/layout/opaque_node.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,16 +7,12 @@
|
||||||
use construct::ConstructionResult;
|
use construct::ConstructionResult;
|
||||||
use incremental::RestyleDamage;
|
use incremental::RestyleDamage;
|
||||||
use parallel::DomParallelInfo;
|
use parallel::DomParallelInfo;
|
||||||
use wrapper::{LayoutNode, TLayoutNode, ThreadSafeLayoutNode};
|
use wrapper::{LayoutNode, TLayoutNode};
|
||||||
|
|
||||||
use azure::azure_hl::Color;
|
use azure::azure_hl::Color;
|
||||||
use gfx::display_list::OpaqueNode;
|
|
||||||
use gfx;
|
use gfx;
|
||||||
use libc::{c_void, uintptr_t};
|
use script::dom::node::SharedLayoutData;
|
||||||
use script::dom::bindings::js::LayoutJS;
|
use script::layout_interface::LayoutChan;
|
||||||
use script::dom::node::{Node, SharedLayoutData};
|
|
||||||
use script::layout_interface::{LayoutChan, TrustedNodeAddress};
|
|
||||||
use script_traits::UntrustedNodeAddress;
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::cell::{Ref, RefMut};
|
use std::cell::{Ref, RefMut};
|
||||||
use style::properties::ComputedValues;
|
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.
|
/// Allows a CSS color to be converted into a graphics color.
|
||||||
pub trait ToGfxColor {
|
pub trait ToGfxColor {
|
||||||
/// Converts a CSS color to a graphics color.
|
/// Converts a CSS color to a graphics color.
|
||||||
|
|
|
@ -36,8 +36,9 @@ use canvas::canvas_paint_task::CanvasMsg;
|
||||||
use context::SharedLayoutContext;
|
use context::SharedLayoutContext;
|
||||||
use css::node_style::StyledNode;
|
use css::node_style::StyledNode;
|
||||||
use incremental::RestyleDamage;
|
use incremental::RestyleDamage;
|
||||||
use util::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper, OpaqueNodeMethods};
|
use util::{LayoutDataAccess, LayoutDataFlags, LayoutDataWrapper};
|
||||||
use util::{PrivateLayoutData};
|
use util::{PrivateLayoutData};
|
||||||
|
use opaque_node::OpaqueNodeMethods;
|
||||||
|
|
||||||
use cssparser::RGBA;
|
use cssparser::RGBA;
|
||||||
use gfx::display_list::OpaqueNode;
|
use gfx::display_list::OpaqueNode;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue