Replace SpecifiedStyle with SelectResults in the aux pointer. Further disable old styling code

This commit is contained in:
Brian Anderson 2012-10-31 15:14:12 -07:00
parent c0350e7739
commit 2c2ad1018a
5 changed files with 45 additions and 51 deletions

View file

@ -5,7 +5,7 @@ use std::arc::{ARC, get, clone};
use core::dvec::DVec; use core::dvec::DVec;
use newcss::values::*; use newcss::values::*;
use newcss::SelectCtx; use newcss::{SelectCtx, SelectResults};
use dom::element::{HTMLDivElement, HTMLHeadElement, HTMLImageElement, UnknownElement, HTMLScriptElement}; use dom::element::{HTMLDivElement, HTMLHeadElement, HTMLImageElement, UnknownElement, HTMLScriptElement};
use dom::node::{Comment, Doctype, Element, Text, use dom::node::{Comment, Doctype, Element, Text,
Node, NodeKind, NodeTree, LayoutData}; Node, NodeKind, NodeTree, LayoutData};
@ -105,7 +105,7 @@ fn empty_style_for_node_kind(kind: &NodeKind) -> SpecifiedStyle {
trait StyleMethods { trait StyleMethods {
fn initialize_layout_data() -> Option<@LayoutData>; fn initialize_layout_data() -> Option<@LayoutData>;
fn style() -> &self/SpecifiedStyle; fn style() -> &self/SelectResults;
fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>); fn initialize_style_for_subtree(ctx: &LayoutContext, refs: &DVec<@LayoutData>);
fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &SelectCtx); fn recompute_style_for_subtree(ctx: &LayoutContext, styles : &SelectCtx);
} }
@ -117,9 +117,8 @@ impl Node : StyleMethods {
fn initialize_layout_data() -> Option<@LayoutData> { fn initialize_layout_data() -> Option<@LayoutData> {
match self.has_aux() { match self.has_aux() {
false => { false => {
let node_kind = self.read(|n| copy *n.kind);
let data = @LayoutData({ let data = @LayoutData({
mut style : ~empty_style_for_node_kind(&node_kind), mut style : None,
mut flow : None mut flow : None
}); });
self.set_aux(data); Some(data) self.set_aux(data); Some(data)
@ -130,15 +129,21 @@ impl Node : StyleMethods {
/** /**
* Provides the computed style for the given node. If CSS selector * 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. * matching has not yet been performed, fails.
* FIXME: This isn't completely memory safe since the style is * FIXME: This isn't completely memory safe since the style is
* stored in a box that can be overwritten * stored in a box that can be overwritten
*/ */
fn style() -> &self/SpecifiedStyle { fn style() -> &self/SelectResults {
if !self.has_aux() { if !self.has_aux() {
fail ~"get_style() called on a node without a style!"; fail ~"style() called on a node without aux data!";
} }
unsafe { &*self.aux( |x| ptr::to_unsafe_ptr(&*x.style) ) } unsafe { &*self.aux( |x| {
match x.style {
Some(ref style) => ptr::to_unsafe_ptr(style),
None => fail ~"style() called on node without a style!"
}
})}
} }
/** /**

View file

@ -1,6 +1,5 @@
/* The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements. */ /* The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements. */
use css::styles::SpecifiedStyle; use newcss::SelectResults;
use newcss::values::Stylesheet;
use dom::bindings; use dom::bindings;
use dom::document::Document; use dom::document::Document;
use dom::element::{Attr, ElementData}; use dom::element::{Attr, ElementData};
@ -113,7 +112,7 @@ fn define_bindings(compartment: &bare_compartment, doc: @Document,
Note that there may be multiple boxes per DOM node. */ Note that there may be multiple boxes per DOM node. */
enum LayoutData = { enum LayoutData = {
mut style: ~SpecifiedStyle, mut style: Option<SelectResults>,
mut flow: Option<@FlowContext> mut flow: Option<@FlowContext>
}; };

View file

@ -385,22 +385,7 @@ impl RenderBox : RenderBoxMethods {
offset: &Point2D<Au>, list: &mut DisplayList) { offset: &Point2D<Au>, list: &mut DisplayList) {
let style = self.d().node.style(); let style = self.d().node.style();
let box_bounds : Rect<Au> = match style.position { let box_bounds = self.d().position;
Specified(PosAbsolute) => {
let x_offset = match style.left {
Specified(Px(px)) => au::from_frac_px(px),
_ => self.d().position.origin.x
};
let y_offset = match style.top {
Specified(Px(px)) => au::from_frac_px(px),
_ => self.d().position.origin.y
};
Rect(Point2D(x_offset, y_offset), copy self.d().position.size)
}
_ => {
self.d().position
}
};
let abs_box_bounds = box_bounds.translate(offset); let abs_box_bounds = box_bounds.translate(offset);
debug!("RenderBox::build_display_list at rel=%?, abs=%?: %s", debug!("RenderBox::build_display_list at rel=%?, abs=%?: %s",
@ -443,19 +428,21 @@ impl RenderBox : RenderBoxMethods {
fn add_bgcolor_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) { fn add_bgcolor_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) {
use std::cmp::FuzzyEq; use std::cmp::FuzzyEq;
// TODO: shouldn't need to unbox CSSValue by now // FIXME
let boxed_bgcolor = self.d().node.style().background_color; /*let boxed_bgcolor = self.d().node.style().background_color;
let bgcolor = match boxed_bgcolor { let bgcolor = match boxed_bgcolor {
Specified(BgColor(c)) => c, Specified(BgColor(c)) => c,
Specified(BgColorTransparent) | _ => rgba(0,0,0,0.0) Specified(BgColorTransparent) | _ => rgba(0,0,0,0.0)
}; };*/
let bgcolor = rgba(0,0,0,0.0);
if !bgcolor.alpha.fuzzy_eq(&0.0) { if !bgcolor.alpha.fuzzy_eq(&0.0) {
list.append_item(~DisplayItem::new_SolidColor(abs_bounds, bgcolor.red, bgcolor.green, bgcolor.blue)); list.append_item(~DisplayItem::new_SolidColor(abs_bounds, bgcolor.red, bgcolor.green, bgcolor.blue));
} }
} }
fn add_border_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) { fn add_border_to_list(list: &mut DisplayList, abs_bounds: &Rect<Au>) {
let style = self.d().node.style(); // FIXME
/*let style = self.d().node.style();
match style.border_width { match style.border_width {
Specified(Px(copy px)) => { Specified(Px(copy px)) => {
// If there's a border, let's try to display *something* // If there's a border, let's try to display *something*
@ -478,7 +465,7 @@ impl RenderBox : RenderBoxMethods {
color.green, color.blue)); color.green, color.blue));
} }
_ => () // TODO _ => () // TODO
} }*/
} }
} }

View file

@ -46,12 +46,14 @@ enum InlineSpacerSide {
priv fn simulate_UA_display_rules(node: Node) -> CSSDisplay { priv fn simulate_UA_display_rules(node: Node) -> CSSDisplay {
let resolved = do node.aux |nd| { // FIXME
/*let resolved = do node.aux |nd| {
match nd.style.display_type { match nd.style.display_type {
Inherit | Initial => DisplayInline, // TODO: remove once resolve works Inherit | Initial => DisplayInline, // TODO: remove once resolve works
Specified(v) => v Specified(v) => v
} }
}; };*/
let resolved = DisplayInline;
if (resolved == DisplayNone) { return resolved; } if (resolved == DisplayNone) { return resolved; }
do node.read |n| { do node.read |n| {

View file

@ -228,8 +228,8 @@ impl Layout {
reply_chan: comm::Chan<LayoutQueryResponse>) { reply_chan: comm::Chan<LayoutQueryResponse>) {
match query { match query {
ContentBox(node) => { ContentBox(node) => {
// TODO: extract me to a method when I get sibling arms let response = do node.aux |a| {
let response = match node.aux(|a| copy *a).flow { match a.flow {
None => Err(()), None => Err(()),
Some(flow) => { Some(flow) => {
let start_val : Option<Rect<Au>> = None; let start_val : Option<Rect<Au>> = None;
@ -249,6 +249,7 @@ impl Layout {
} }
} }
} }
}
}; };
reply_chan.send(response) reply_chan.send(response)