From 2c2ad1018ae8af690377e264ab2a1a18e9a17ca2 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Wed, 31 Oct 2012 15:14:12 -0700 Subject: [PATCH] Replace SpecifiedStyle with SelectResults in the aux pointer. Further disable old styling code --- src/servo/css/styles.rs | 19 ++++++++++------- src/servo/dom/node.rs | 5 ++--- src/servo/layout/box.rs | 29 +++++++------------------- src/servo/layout/box_builder.rs | 6 ++++-- src/servo/layout/layout_task.rs | 37 +++++++++++++++++---------------- 5 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/servo/css/styles.rs b/src/servo/css/styles.rs index 7aade2f0b97..574a4d80b2e 100644 --- a/src/servo/css/styles.rs +++ b/src/servo/css/styles.rs @@ -5,7 +5,7 @@ use std::arc::{ARC, get, clone}; use core::dvec::DVec; use newcss::values::*; -use newcss::SelectCtx; +use newcss::{SelectCtx, SelectResults}; use dom::element::{HTMLDivElement, HTMLHeadElement, HTMLImageElement, UnknownElement, HTMLScriptElement}; use dom::node::{Comment, Doctype, Element, Text, Node, NodeKind, NodeTree, LayoutData}; @@ -105,7 +105,7 @@ fn empty_style_for_node_kind(kind: &NodeKind) -> SpecifiedStyle { trait StyleMethods { 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 recompute_style_for_subtree(ctx: &LayoutContext, styles : &SelectCtx); } @@ -117,9 +117,8 @@ impl Node : StyleMethods { fn initialize_layout_data() -> Option<@LayoutData> { match self.has_aux() { false => { - let node_kind = self.read(|n| copy *n.kind); let data = @LayoutData({ - mut style : ~empty_style_for_node_kind(&node_kind), + mut style : None, mut flow : None }); self.set_aux(data); Some(data) @@ -130,15 +129,21 @@ impl Node : StyleMethods { /** * 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/SpecifiedStyle { + fn style() -> &self/SelectResults { 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!" + } + })} } /** diff --git a/src/servo/dom/node.rs b/src/servo/dom/node.rs index e72ad515792..ec5fe4910da 100644 --- a/src/servo/dom/node.rs +++ b/src/servo/dom/node.rs @@ -1,6 +1,5 @@ /* The core DOM types. Defines the basic DOM hierarchy as well as all the HTML elements. */ -use css::styles::SpecifiedStyle; -use newcss::values::Stylesheet; +use newcss::SelectResults; use dom::bindings; use dom::document::Document; 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. */ enum LayoutData = { - mut style: ~SpecifiedStyle, + mut style: Option, mut flow: Option<@FlowContext> }; diff --git a/src/servo/layout/box.rs b/src/servo/layout/box.rs index 457e70e0a0b..2c5e8723790 100644 --- a/src/servo/layout/box.rs +++ b/src/servo/layout/box.rs @@ -385,22 +385,7 @@ impl RenderBox : RenderBoxMethods { offset: &Point2D, list: &mut DisplayList) { let style = self.d().node.style(); - let box_bounds : Rect = match style.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 box_bounds = self.d().position; let abs_box_bounds = box_bounds.translate(offset); 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) { use std::cmp::FuzzyEq; - // TODO: shouldn't need to unbox CSSValue by now - let boxed_bgcolor = self.d().node.style().background_color; + // FIXME + /*let boxed_bgcolor = self.d().node.style().background_color; let bgcolor = match boxed_bgcolor { Specified(BgColor(c)) => c, Specified(BgColorTransparent) | _ => rgba(0,0,0,0.0) - }; + };*/ + let bgcolor = rgba(0,0,0,0.0); if !bgcolor.alpha.fuzzy_eq(&0.0) { 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) { - let style = self.d().node.style(); + // FIXME + /*let style = self.d().node.style(); match style.border_width { Specified(Px(copy px)) => { // If there's a border, let's try to display *something* @@ -478,7 +465,7 @@ impl RenderBox : RenderBoxMethods { color.green, color.blue)); } _ => () // TODO - } + }*/ } } diff --git a/src/servo/layout/box_builder.rs b/src/servo/layout/box_builder.rs index 783a5c8f057..5e77e97f6ec 100644 --- a/src/servo/layout/box_builder.rs +++ b/src/servo/layout/box_builder.rs @@ -46,12 +46,14 @@ enum InlineSpacerSide { 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 { Inherit | Initial => DisplayInline, // TODO: remove once resolve works Specified(v) => v } - }; + };*/ + let resolved = DisplayInline; if (resolved == DisplayNone) { return resolved; } do node.read |n| { diff --git a/src/servo/layout/layout_task.rs b/src/servo/layout/layout_task.rs index dbbbb33e1e6..eabae411b1e 100644 --- a/src/servo/layout/layout_task.rs +++ b/src/servo/layout/layout_task.rs @@ -228,24 +228,25 @@ impl Layout { reply_chan: comm::Chan) { match query { ContentBox(node) => { - // TODO: extract me to a method when I get sibling arms - let response = match node.aux(|a| copy *a).flow { - None => Err(()), - Some(flow) => { - let start_val : Option> = None; - let rect = do flow.foldl_boxes_for_node(node, start_val) |acc, box| { - match acc { - Some(acc) => Some(acc.union(&box.content_box())), - None => Some(box.content_box()) - } - }; - - match rect { - None => Err(()), - Some(rect) => { - let size = Size2D(au::to_px(rect.size.width), - au::to_px(rect.size.height)); - Ok(ContentSize(move size)) + let response = do node.aux |a| { + match a.flow { + None => Err(()), + Some(flow) => { + let start_val : Option> = None; + let rect = do flow.foldl_boxes_for_node(node, start_val) |acc, box| { + match acc { + Some(acc) => Some(acc.union(&box.content_box())), + None => Some(box.content_box()) + } + }; + + match rect { + None => Err(()), + Some(rect) => { + let size = Size2D(au::to_px(rect.size.width), + au::to_px(rect.size.height)); + Ok(ContentSize(move size)) + } } } }