mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
Replace SpecifiedStyle with SelectResults in the aux pointer. Further disable old styling code
This commit is contained in:
parent
c0350e7739
commit
2c2ad1018a
5 changed files with 45 additions and 51 deletions
|
@ -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!"
|
||||
}
|
||||
})}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<SelectResults>,
|
||||
mut flow: Option<@FlowContext>
|
||||
};
|
||||
|
||||
|
|
|
@ -385,22 +385,7 @@ impl RenderBox : RenderBoxMethods {
|
|||
offset: &Point2D<Au>, list: &mut DisplayList) {
|
||||
|
||||
let style = self.d().node.style();
|
||||
let box_bounds : Rect<Au> = 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<Au>) {
|
||||
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<Au>) {
|
||||
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
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -228,24 +228,25 @@ impl Layout {
|
|||
reply_chan: comm::Chan<LayoutQueryResponse>) {
|
||||
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<Rect<Au>> = 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<Rect<Au>> = 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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue