mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
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.
This commit is contained in:
parent
f9642b36bd
commit
bf9369b29d
17 changed files with 128 additions and 166 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue