mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Move node style getter/setter to css::node_util
This commit is contained in:
parent
fafe3883ef
commit
5c606a8dbb
5 changed files with 42 additions and 40 deletions
|
@ -9,7 +9,7 @@ use newcss::values::*;
|
|||
use newcss::{SelectCtx, SelectResults};
|
||||
use styles::{SpecifiedStyle};
|
||||
use select_handler::NodeSelectHandler;
|
||||
use std::cell::Cell;
|
||||
use node_util::NodeUtil;
|
||||
|
||||
/**
|
||||
Check if a CSS attribute matches the attribute of an HTML element.
|
||||
|
@ -168,22 +168,6 @@ impl Node : PrivMatchingMethods {
|
|||
}
|
||||
}
|
||||
|
||||
trait PrivStyleMethods {
|
||||
fn update_style(decl : SelectResults);
|
||||
}
|
||||
|
||||
impl Node : PrivStyleMethods {
|
||||
/**
|
||||
Update the computed style of an HTML element with a style specified by CSS.
|
||||
*/
|
||||
fn update_style(decl : SelectResults) {
|
||||
let decl = Cell(move decl);
|
||||
do self.aux |data| {
|
||||
data.style = Some(decl.take())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
trait MatchingMethods {
|
||||
fn match_css_style(select_ctx : &SelectCtx);
|
||||
}
|
||||
|
@ -204,7 +188,7 @@ impl Node : MatchingMethods {
|
|||
node: self
|
||||
};
|
||||
let style = select_ctx.select_style(&self, &select_handler);
|
||||
self.update_style(move style);
|
||||
self.set_style(move style);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
39
src/servo/css/node_util.rs
Normal file
39
src/servo/css/node_util.rs
Normal file
|
@ -0,0 +1,39 @@
|
|||
use dom::node::Node;
|
||||
use newcss::SelectResults;
|
||||
use std::cell::Cell;
|
||||
|
||||
trait NodeUtil {
|
||||
fn get_style() -> &self/SelectResults;
|
||||
fn set_style(decl : SelectResults);
|
||||
}
|
||||
|
||||
impl Node: NodeUtil {
|
||||
/**
|
||||
* Provides the computed style for the given node. If CSS selector
|
||||
* Returns the style results for the given node. If CSS selector
|
||||
* matching has not yet been performed, fails.
|
||||
* FIXME: This isn't completely memory safe since the style is
|
||||
* stored in a box that can be overwritten
|
||||
*/
|
||||
fn get_style() -> &self/SelectResults {
|
||||
if !self.has_aux() {
|
||||
fail ~"style() called on a node without aux data!";
|
||||
}
|
||||
unsafe { &*self.aux( |x| {
|
||||
match x.style {
|
||||
Some(ref style) => ptr::to_unsafe_ptr(style),
|
||||
None => fail ~"style() called on node without a style!"
|
||||
}
|
||||
})}
|
||||
}
|
||||
|
||||
/**
|
||||
Update the computed style of an HTML element with a style specified by CSS.
|
||||
*/
|
||||
fn set_style(decl : SelectResults) {
|
||||
let decl = Cell(move decl);
|
||||
do self.aux |data| {
|
||||
data.style = Some(decl.take())
|
||||
}
|
||||
}
|
||||
}
|
|
@ -104,8 +104,6 @@ fn empty_style_for_node_kind(kind: &NodeKind) -> SpecifiedStyle {
|
|||
|
||||
trait StyleMethods {
|
||||
fn initialize_layout_data() -> Option<@LayoutData>;
|
||||
|
||||
fn style() -> &self/SelectResults;
|
||||
fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>);
|
||||
fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &SelectCtx);
|
||||
}
|
||||
|
@ -126,25 +124,6 @@ impl Node : StyleMethods {
|
|||
true => None
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides the computed style for the given node. If CSS selector
|
||||
* Returns the style results for the given node. If CSS selector
|
||||
* matching has not yet been performed, fails.
|
||||
* FIXME: This isn't completely memory safe since the style is
|
||||
* stored in a box that can be overwritten
|
||||
*/
|
||||
fn style() -> &self/SelectResults {
|
||||
if !self.has_aux() {
|
||||
fail ~"style() called on a node without aux data!";
|
||||
}
|
||||
unsafe { &*self.aux( |x| {
|
||||
match x.style {
|
||||
Some(ref style) => ptr::to_unsafe_ptr(style),
|
||||
None => fail ~"style() called on node without a style!"
|
||||
}
|
||||
})}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes layout data and styles for a Node tree, if any nodes do not have
|
||||
|
|
|
@ -385,7 +385,6 @@ impl RenderBox : RenderBoxMethods {
|
|||
fn build_display_list(@self, builder: &DisplayListBuilder, dirty: &Rect<Au>,
|
||||
offset: &Point2D<Au>, list: &mut DisplayList) {
|
||||
|
||||
let style = self.d().node.style();
|
||||
let box_bounds = self.d().position;
|
||||
|
||||
let abs_box_bounds = box_bounds.translate(offset);
|
||||
|
|
|
@ -50,6 +50,7 @@ pub mod css {
|
|||
mod matching;
|
||||
priv mod select_handler;
|
||||
pub mod compute;
|
||||
priv mod node_util;
|
||||
}
|
||||
|
||||
pub mod layout {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue