Change StyleMethods::style to return a region pointer instead of copying the style object

This commit is contained in:
Brian Anderson 2012-10-31 14:27:40 -07:00
parent b00885f77a
commit c0350e7739
2 changed files with 7 additions and 6 deletions

View file

@ -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() -> SpecifiedStyle; fn style() -> &self/SpecifiedStyle;
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);
} }
@ -129,15 +129,16 @@ impl Node : StyleMethods {
} }
/** /**
* Returns the computed style for the given node. If CSS selector * Provides the computed style 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
* stored in a box that can be overwritten
*/ */
fn style() -> SpecifiedStyle { fn style() -> &self/SpecifiedStyle {
if !self.has_aux() { if !self.has_aux() {
fail ~"get_style() called on a node without a style!"; fail ~"get_style() called on a node without a style!";
} }
// TODO: return a safe reference; don't copy! unsafe { &*self.aux( |x| ptr::to_unsafe_ptr(&*x.style) ) }
return copy *self.aux(|x| copy *x).style;
} }
/** /**

View file

@ -457,7 +457,7 @@ impl RenderBox : RenderBoxMethods {
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(); let style = self.d().node.style();
match style.border_width { match style.border_width {
Specified(Px(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*
let border_width = au::from_frac_px(px); let border_width = au::from_frac_px(px);
let abs_bounds = Rect { let abs_bounds = Rect {