mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Remove a layer of Option on LayoutData
The individual fields are also Options, and LayoutData::new() is a fine default value.
This commit is contained in:
parent
c22547a4ef
commit
51c639c380
4 changed files with 10 additions and 49 deletions
|
@ -27,10 +27,6 @@ impl<'self> NodeUtil<'self> for AbstractNode<LayoutView> {
|
|||
* stored in a box that can be overwritten
|
||||
*/
|
||||
fn get_css_select_results(self) -> &'self CompleteSelectResults {
|
||||
if !self.has_layout_data() {
|
||||
fail!(~"style() called on a node without aux data!");
|
||||
}
|
||||
|
||||
do self.read_layout_data |layout_data| {
|
||||
match layout_data.style {
|
||||
None => fail!(~"style() called on node without a style!"),
|
||||
|
@ -41,18 +37,11 @@ impl<'self> NodeUtil<'self> for AbstractNode<LayoutView> {
|
|||
|
||||
/// Does this node have a computed style yet?
|
||||
fn have_css_select_results(self) -> bool {
|
||||
if !self.has_layout_data() {
|
||||
return false;
|
||||
}
|
||||
self.read_layout_data(|data| data.style.is_some())
|
||||
}
|
||||
|
||||
/// Update the computed style of an HTML element with a style specified by CSS.
|
||||
fn set_css_select_results(self, decl: CompleteSelectResults) {
|
||||
if !self.has_layout_data() {
|
||||
fail!(~"set_css_select_results() called on a node without aux data!");
|
||||
}
|
||||
|
||||
let cell = Cell::new(decl);
|
||||
self.write_layout_data(|data| data.style = Some(cell.take()));
|
||||
}
|
||||
|
@ -68,9 +57,6 @@ impl<'self> NodeUtil<'self> for AbstractNode<LayoutView> {
|
|||
RestyleDamage::none()
|
||||
};
|
||||
|
||||
if !self.has_layout_data() {
|
||||
return default;
|
||||
}
|
||||
do self.read_layout_data |layout_data| {
|
||||
layout_data.restyle_damage
|
||||
.map(|&x| RestyleDamage::from_int(x))
|
||||
|
@ -80,10 +66,6 @@ impl<'self> NodeUtil<'self> for AbstractNode<LayoutView> {
|
|||
|
||||
/// Set the restyle damage field.
|
||||
fn set_restyle_damage(self, damage: RestyleDamage) {
|
||||
if !self.has_layout_data() {
|
||||
fail!(~"set_restyle_damage() called on a node without aux data!");
|
||||
}
|
||||
|
||||
self.write_layout_data(|data| data.restyle_damage = Some(damage.to_int()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
//! Code for managing the layout data in the DOM.
|
||||
|
||||
use script::dom::node::{AbstractNode, LayoutView, LayoutData};
|
||||
use script::dom::node::{AbstractNode, LayoutView};
|
||||
use servo_util::tree::TreeNodeRef;
|
||||
|
||||
/// Functionality useful for querying the layout-specific data on DOM nodes.
|
||||
|
@ -14,21 +14,15 @@ pub trait LayoutAuxMethods {
|
|||
}
|
||||
|
||||
impl LayoutAuxMethods for AbstractNode<LayoutView> {
|
||||
/// If none exists, creates empty layout data for the node (the reader-auxiliary
|
||||
/// box in the COW model) and populates it with an empty style object.
|
||||
/// Resets layout data and styles for the node.
|
||||
fn initialize_layout_data(self) {
|
||||
if self.has_layout_data() {
|
||||
do self.write_layout_data |data| {
|
||||
data.boxes.display_list = None;
|
||||
data.boxes.range = None;
|
||||
}
|
||||
} else {
|
||||
self.set_layout_data(LayoutData::new());
|
||||
do self.write_layout_data |data| {
|
||||
data.boxes.display_list = None;
|
||||
data.boxes.range = None;
|
||||
}
|
||||
}
|
||||
|
||||
/// Initializes layout data and styles for a Node tree, if any nodes do not have
|
||||
/// this data already.
|
||||
/// Resets layout data and styles for a Node tree.
|
||||
fn initialize_style_for_subtree(self) {
|
||||
for n in self.traverse_preorder() {
|
||||
n.initialize_layout_data();
|
||||
|
|
|
@ -322,7 +322,6 @@ impl LayoutTask {
|
|||
let node: AbstractNode<LayoutView> = unsafe {
|
||||
transmute(display_list.get().list[i].base().extra)
|
||||
};
|
||||
assert!(node.has_layout_data(), "Node has display item but no layout data");
|
||||
|
||||
do node.write_layout_data |layout_data| {
|
||||
layout_data.boxes.display_list = Some(display_list.clone());
|
||||
|
|
|
@ -16,7 +16,6 @@ use dom::htmliframeelement::HTMLIFrameElement;
|
|||
use dom::text::Text;
|
||||
|
||||
use std::cast;
|
||||
use std::cell::Cell;
|
||||
use std::cast::transmute;
|
||||
use std::libc::c_void;
|
||||
use extra::arc::Arc;
|
||||
|
@ -90,7 +89,7 @@ pub struct Node<View> {
|
|||
owner_doc: Option<AbstractDocument>,
|
||||
|
||||
/// Layout information. Only the layout task may touch this data.
|
||||
priv layout_data: Option<LayoutData>,
|
||||
priv layout_data: LayoutData,
|
||||
}
|
||||
|
||||
/// The different types of nodes.
|
||||
|
@ -415,7 +414,7 @@ impl Node<ScriptView> {
|
|||
|
||||
owner_doc: None,
|
||||
|
||||
layout_data: None,
|
||||
layout_data: LayoutData::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -644,32 +643,19 @@ impl LayoutData {
|
|||
}
|
||||
|
||||
impl AbstractNode<LayoutView> {
|
||||
pub fn set_layout_data(self, data: LayoutData) {
|
||||
let cell = Cell::new(data);
|
||||
do self.with_mut_base |b| {
|
||||
b.layout_data = Some(cell.take());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn has_layout_data(self) -> bool {
|
||||
do self.with_base |b| {
|
||||
b.layout_data.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
// These accessors take a continuation rather than returning a reference, because
|
||||
// an AbstractNode doesn't have a lifetime parameter relating to the underlying
|
||||
// Node. Also this makes it easier to switch to RWArc if we decide that is
|
||||
// necessary.
|
||||
pub fn read_layout_data<R>(self, blk: &fn(data: &LayoutData) -> R) -> R {
|
||||
do self.with_base |b| {
|
||||
blk(b.layout_data.get_ref())
|
||||
blk(&b.layout_data)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_layout_data<R>(self, blk: &fn(data: &mut LayoutData) -> R) -> R {
|
||||
do self.with_mut_base |b| {
|
||||
blk(b.layout_data.get_mut_ref())
|
||||
blk(&mut b.layout_data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue