aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout
diff options
context:
space:
mode:
authorEmilio Cobos Álvarez <emilio@crisal.io>2017-07-15 15:44:45 +0200
committerEmilio Cobos Álvarez <emilio@crisal.io>2017-07-15 16:41:12 +0200
commitbf9369b29d42255ea52b172e3ddd9b44db922d44 (patch)
tree46ade80599ca2cd87eeb68a98a8992aefa421dcc /components/layout
parentf9642b36bda3beb01dfedbc33e3586e5f7df473a (diff)
downloadservo-bf9369b29d42255ea52b172e3ddd9b44db922d44.tar.gz
servo-bf9369b29d42255ea52b172e3ddd9b44db922d44.zip
script: Move the layout_wrapper outside of script.
This allows us to have ensure_data() and clear_data() functions on the TElement trait, instead of hacking around it adding methods in random traits. This also allows us to do some further cleanup, which I'd rather do in a followup.
Diffstat (limited to 'components/layout')
-rw-r--r--components/layout/lib.rs3
-rw-r--r--components/layout/traversal.rs15
-rw-r--r--components/layout/wrapper.rs34
3 files changed, 4 insertions, 48 deletions
diff --git a/components/layout/lib.rs b/components/layout/lib.rs
index 868892ea0a5..3527c3590cd 100644
--- a/components/layout/lib.rs
+++ b/components/layout/lib.rs
@@ -14,7 +14,6 @@ extern crate atomic_refcell;
#[macro_use]
extern crate bitflags;
extern crate canvas_traits;
-extern crate core;
extern crate euclid;
extern crate fnv;
extern crate gfx;
@@ -55,7 +54,7 @@ pub mod animation;
mod block;
pub mod construct;
pub mod context;
-mod data;
+pub mod data;
pub mod display_list_builder;
mod flex;
mod floats;
diff --git a/components/layout/traversal.rs b/components/layout/traversal.rs
index f011925ebb8..cf75a47bbf8 100644
--- a/components/layout/traversal.rs
+++ b/components/layout/traversal.rs
@@ -4,7 +4,6 @@
//! Traversals over the DOM and flow trees, running the layout computations.
-use atomic_refcell::AtomicRefCell;
use construct::FlowConstructor;
use context::LayoutContext;
use display_list_builder::DisplayListBuildState;
@@ -13,13 +12,12 @@ use flow::{CAN_BE_FRAGMENTED, Flow, ImmutableFlowUtils, PostorderFlowTraversal};
use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutNode};
use servo_config::opts;
use style::context::{SharedStyleContext, StyleContext};
-use style::data::ElementData;
use style::dom::{NodeInfo, TElement, TNode};
use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT};
use style::traversal::{DomTraversal, TraversalDriver, recalc_style_at};
use style::traversal::PerLevelTraversalData;
-use wrapper::{GetRawData, LayoutNodeHelpers, LayoutNodeLayoutData};
+use wrapper::{GetRawData, LayoutNodeLayoutData};
use wrapper::ThreadSafeLayoutNodeHelpers;
pub struct RecalcStyleAndConstructFlows<'a> {
@@ -59,7 +57,7 @@ impl<'a, E> DomTraversal<E> for RecalcStyleAndConstructFlows<'a>
context: &mut StyleContext<E>, node: E::ConcreteNode) {
// FIXME(pcwalton): Stop allocating here. Ideally this should just be
// done by the HTML parser.
- node.initialize_data();
+ unsafe { node.initialize_data() };
if !node.is_text_node() {
let el = node.as_element().unwrap();
@@ -81,15 +79,6 @@ impl<'a, E> DomTraversal<E> for RecalcStyleAndConstructFlows<'a>
node.parent_node().unwrap().to_threadsafe().restyle_damage() != RestyleDamage::empty()
}
- unsafe fn ensure_element_data(element: &E) -> &AtomicRefCell<ElementData> {
- element.as_node().initialize_data();
- element.get_data().unwrap()
- }
-
- unsafe fn clear_element_data(element: &E) {
- element.as_node().clear_data();
- }
-
fn shared_context(&self) -> &SharedStyleContext {
&self.context.style_context
}
diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs
index 87fe65bb3b9..2a31e17cfa1 100644
--- a/components/layout/wrapper.rs
+++ b/components/layout/wrapper.rs
@@ -31,21 +31,13 @@
#![allow(unsafe_code)]
use atomic_refcell::{AtomicRef, AtomicRefMut};
-use core::nonzero::NonZero;
use data::{LayoutData, LayoutDataFlags, StyleAndLayoutData};
-use script_layout_interface::{OpaqueStyleAndLayoutData, StyleData};
-use script_layout_interface::wrapper_traits::{LayoutNode, ThreadSafeLayoutElement, ThreadSafeLayoutNode};
+use script_layout_interface::wrapper_traits::{ThreadSafeLayoutElement, ThreadSafeLayoutNode};
use script_layout_interface::wrapper_traits::GetLayoutData;
use style::computed_values::content::{self, ContentItem};
use style::dom::{NodeInfo, TNode};
use style::selector_parser::RestyleDamage;
-pub unsafe fn drop_style_and_layout_data(data: OpaqueStyleAndLayoutData) {
- let ptr: *mut StyleData = data.ptr.get();
- let non_opaque: *mut StyleAndLayoutData = ptr as *mut _;
- let _ = Box::from_raw(non_opaque);
-}
-
pub trait LayoutNodeLayoutData {
/// Similar to borrow_data*, but returns the full PersistentLayoutData rather
/// than only the style::data::ElementData.
@@ -81,30 +73,6 @@ impl<T: GetLayoutData> GetRawData for T {
}
}
-pub trait LayoutNodeHelpers {
- fn initialize_data(&self);
- fn clear_data(&self);
-}
-
-impl<T: LayoutNode> LayoutNodeHelpers for T {
- fn initialize_data(&self) {
- if self.get_raw_data().is_none() {
- let ptr: *mut StyleAndLayoutData =
- Box::into_raw(Box::new(StyleAndLayoutData::new()));
- let opaque = OpaqueStyleAndLayoutData {
- ptr: unsafe { NonZero::new(ptr as *mut StyleData) }
- };
- unsafe { self.init_style_and_layout_data(opaque) };
- };
- }
-
- fn clear_data(&self) {
- if self.get_raw_data().is_some() {
- unsafe { drop_style_and_layout_data(self.take_style_and_layout_data()) };
- }
- }
-}
-
pub trait ThreadSafeLayoutNodeHelpers {
/// Returns the layout data flags for this node.
fn flags(self) -> LayoutDataFlags;