Skip to content

Commit

Permalink
removing @ from flowtree. (but cloning boxes when creating a display …
Browse files Browse the repository at this point in the history
…list)
  • Loading branch information
ryanhc committed Dec 10, 2013
1 parent 6014bd3 commit d26bf36
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 158 deletions.
13 changes: 7 additions & 6 deletions src/components/gfx/display_list.rs
Expand Up @@ -93,7 +93,7 @@ pub struct SolidColorDisplayItem<E> {
/// Renders text.
pub struct TextDisplayItem<E> {
base: BaseDisplayItem<E>,
text_run: ~TextRun,
text_run: Arc<~TextRun>,
range: Range,
color: Color,
}
Expand Down Expand Up @@ -163,7 +163,8 @@ impl<E> DisplayItem<E> {
debug!("Drawing text at {:?}.", text.base.bounds);

// FIXME(pcwalton): Allocating? Why?
let font = render_context.font_ctx.get_font_by_descriptor(&text.text_run.font_descriptor).unwrap();
let text_run = text.text_run.get();
let font = render_context.font_ctx.get_font_by_descriptor(&text_run.font_descriptor).unwrap();

let font_metrics = font.with_borrow( |font| {
font.metrics.clone()
Expand All @@ -172,7 +173,7 @@ impl<E> DisplayItem<E> {
let baseline_origin = Point2D(origin.x, origin.y + font_metrics.ascent);
font.with_mut_borrow( |font| {
font.draw_text_into_context(render_context,
&text.text_run,
text.text_run.get(),
&text.range,
baseline_origin,
text.color);
Expand All @@ -183,18 +184,18 @@ impl<E> DisplayItem<E> {
let strikeout_size = font_metrics.strikeout_size;
let strikeout_offset = font_metrics.strikeout_offset;

if text.text_run.decoration.underline {
if text_run.decoration.underline {
let underline_y = baseline_origin.y - underline_offset;
let underline_bounds = Rect(Point2D(baseline_origin.x, underline_y),
Size2D(width, underline_size));
render_context.draw_solid_color(&underline_bounds, text.color);
}
if text.text_run.decoration.overline {
if text_run.decoration.overline {
let overline_bounds = Rect(Point2D(baseline_origin.x, origin.y),
Size2D(width, underline_size));
render_context.draw_solid_color(&overline_bounds, text.color);
}
if text.text_run.decoration.line_through {
if text_run.decoration.line_through {
let strikeout_y = baseline_origin.y - strikeout_offset;
let strikeout_bounds = Rect(Point2D(baseline_origin.x, strikeout_y),
Size2D(width, strikeout_size));
Expand Down
64 changes: 32 additions & 32 deletions src/components/main/layout/block.rs
Expand Up @@ -53,7 +53,7 @@ pub struct BlockFlow {
base: FlowData,

/// The associated box.
box: Option<@Box>,
box: Option<~Box>,

/// Whether this block flow is the root flow.
is_root: bool,
Expand All @@ -72,7 +72,7 @@ impl BlockFlow {
}
}

pub fn from_box(base: FlowData, box: @Box) -> BlockFlow {
pub fn from_box(base: FlowData, box: ~Box) -> BlockFlow {
BlockFlow {
base: base,
box: Some(box),
Expand All @@ -81,7 +81,7 @@ impl BlockFlow {
}
}

pub fn float_from_box(base: FlowData, float_type: FloatType, box: @Box) -> BlockFlow {
pub fn float_from_box(base: FlowData, float_type: FloatType, box: ~Box) -> BlockFlow {
BlockFlow {
base: base,
box: Some(box),
Expand Down Expand Up @@ -123,9 +123,9 @@ impl BlockFlow {
/// Computes left and right margins and width based on CSS 2.1 section 10.3.3.
/// Requires borders and padding to already be computed.
fn compute_horiz(&self,
width: MaybeAuto,
left_margin: MaybeAuto,
right_margin: MaybeAuto,
width: MaybeAuto,
left_margin: MaybeAuto,
right_margin: MaybeAuto,
available_width: Au)
-> (Au, Au, Au) {
// If width is not 'auto', and width + margins > available_width, all 'auto' margins are
Expand All @@ -135,7 +135,7 @@ impl BlockFlow {
Specified(width) => {
let left = left_margin.specified_or_zero();
let right = right_margin.specified_or_zero();

if((left + right + width) > available_width) {
(Specified(left), Specified(right))
} else {
Expand All @@ -147,7 +147,7 @@ impl BlockFlow {
//Invariant: left_margin_Au + width_Au + right_margin_Au == available_width
let (left_margin_Au, width_Au, right_margin_Au) = match (left_margin, width, right_margin) {
//If all have a computed value other than 'auto', the system is over-constrained and we need to discard a margin.
//if direction is ltr, ignore the specified right margin and solve for it. If it is rtl, ignore the specified
//if direction is ltr, ignore the specified right margin and solve for it. If it is rtl, ignore the specified
//left margin. FIXME(eatkinson): this assumes the direction is ltr
(Specified(margin_l), Specified(width), Specified(_margin_r)) => (margin_l, width, available_width - (margin_l + width )),

Expand All @@ -172,7 +172,7 @@ impl BlockFlow {
(width_Au, left_margin_Au, right_margin_Au)
}

fn compute_block_margins(&self, box: @Box, remaining_width: Au, available_width: Au)
fn compute_block_margins(&self, box: &Box, remaining_width: Au, available_width: Au)
-> (Au, Au, Au) {
let style = box.style();

Expand Down Expand Up @@ -215,7 +215,7 @@ impl BlockFlow {
return (width, margin_left, margin_right);
}

fn compute_float_margins(&self, box: @Box, remaining_width: Au) -> (Au, Au, Au) {
fn compute_float_margins(&self, box: &Box, remaining_width: Au) -> (Au, Au, Au) {
let style = box.style();
let margin_left = MaybeAuto::from_style(style.Margin.margin_left,
remaining_width).specified_or_zero();
Expand All @@ -240,7 +240,7 @@ impl BlockFlow {
let mut left_offset = Au::new(0);
let mut float_ctx = Invalid;

for &box in self.box.iter() {
for box in self.box.iter() {
clearance = match box.clear() {
None => Au::new(0),
Some(clear) => {
Expand Down Expand Up @@ -279,7 +279,7 @@ impl BlockFlow {
let mut top_margin_collapsible = false;
let mut bottom_margin_collapsible = false;
let mut first_in_flow = true;
for &box in self.box.iter() {
for box in self.box.iter() {
if !self.is_root && box.border.get().top == Au(0) && box.padding.get().top == Au(0) {
collapsible = box.margin.get().top;
top_margin_collapsible = true;
Expand Down Expand Up @@ -316,7 +316,7 @@ impl BlockFlow {
} else {
Au::new(0)
};

// TODO: A box's own margins collapse if the 'min-height' property is zero, and it has neither
// top or bottom borders nor top or bottom padding, and it has a 'height' of either 0 or 'auto',
// and it does not contain a line box, and all of its in-flow children's margins (if any) collapse.
Expand All @@ -328,7 +328,7 @@ impl BlockFlow {
cur_y - top_offset - collapsing
};

for &box in self.box.iter() {
for box in self.box.iter() {
let style = box.style();
height = match MaybeAuto::from_style(style.Box.height, Au::new(0)) {
Auto => height,
Expand Down Expand Up @@ -360,7 +360,7 @@ impl BlockFlow {
self.base.position.size.height = height + noncontent_height;

if inorder {
let extra_height = height - (cur_y - top_offset) + bottom_offset;
let extra_height = height - (cur_y - top_offset) + bottom_offset;
self.base.floats_out = float_ctx.translate(Point2D(left_offset, -extra_height));
} else {
self.base.floats_out = self.base.floats_in.clone();
Expand Down Expand Up @@ -419,7 +419,7 @@ impl BlockFlow {
let mut cur_y = Au(0);
let mut top_offset = Au(0);

for &box in self.box.iter() {
for box in self.box.iter() {
top_offset = box.margin.get().top + box.border.get().top + box.padding.get().top;
cur_y = cur_y + top_offset;
}
Expand All @@ -441,7 +441,7 @@ impl BlockFlow {

noncontent_height = box.padding.get().top + box.padding.get().bottom +
box.border.get().top + box.border.get().bottom;

//TODO(eatkinson): compute heights properly using the 'height' property.
let height_prop = MaybeAuto::from_style(box.style().Box.height,
Au::new(0)).specified_or_zero();
Expand All @@ -456,24 +456,24 @@ impl BlockFlow {
pub fn build_display_list_block<E:ExtraDisplayListData>(
&mut self,
builder: &DisplayListBuilder,
dirty: &Rect<Au>,
list: &Cell<DisplayList<E>>)
dirty: &Rect<Au>,
list: &Cell<DisplayList<E>>)
-> bool {
if self.is_float() {
return self.build_display_list_float(builder, dirty, list);
}

if self.base.node.is_iframe_element() {
let x = self.base.abs_position.x + do self.box.map_default(Au::new(0)) |box| {
let x = self.base.abs_position.x + do self.box.as_ref().map_default(Au::new(0)) |box| {
box.margin.get().left + box.border.get().left + box.padding.get().left
};
let y = self.base.abs_position.y + do self.box.map_default(Au::new(0)) |box| {
let y = self.base.abs_position.y + do self.box.as_ref().map_default(Au::new(0)) |box| {
box.margin.get().top + box.border.get().top + box.padding.get().top
};
let w = self.base.position.size.width - do self.box.map_default(Au::new(0)) |box| {
let w = self.base.position.size.width - do self.box.as_ref().map_default(Au::new(0)) |box| {
box.noncontent_width()
};
let h = self.base.position.size.height - do self.box.map_default(Au::new(0)) |box| {
let h = self.base.position.size.height - do self.box.as_ref().map_default(Au::new(0)) |box| {
box.noncontent_height()
};
do self.base.node.with_mut_iframe_element |iframe_element| {
Expand Down Expand Up @@ -508,8 +508,8 @@ impl BlockFlow {

pub fn build_display_list_float<E:ExtraDisplayListData>(&mut self,
builder: &DisplayListBuilder,
dirty: &Rect<Au>,
list: &Cell<DisplayList<E>>)
dirty: &Rect<Au>,
list: &Cell<DisplayList<E>>)
-> bool {
//TODO: implement iframe size messaging
if self.base.node.is_iframe_element() {
Expand Down Expand Up @@ -627,7 +627,7 @@ impl Flow for BlockFlow {
self.base.is_inorder = false;
}

for &box in self.box.iter() {
for box in self.box.iter() {
let style = box.style();

// Can compute padding here since we know containing block width.
Expand All @@ -643,9 +643,9 @@ impl Flow for BlockFlow {
remaining_width).specified_or_zero();

let (width, margin_left, margin_right) = if self.is_float() {
self.compute_float_margins(box, remaining_width)
self.compute_float_margins(*box, remaining_width)
} else {
self.compute_block_margins(box, remaining_width, available_width)
self.compute_block_margins(*box, remaining_width, available_width)
};

box.margin.set(SideOffsets2D::new(margin_top,
Expand Down Expand Up @@ -727,11 +727,11 @@ impl Flow for BlockFlow {
return;
}

for &box in self.box.iter() {
for box in self.box.iter() {
// The top margin collapses with its first in-flow block-level child's
// top margin if the parent has no top border, no top padding.
if *first_in_flow && top_margin_collapsible {
// If top-margin of parent is less than top-margin of its first child,
// If top-margin of parent is less than top-margin of its first child,
// the parent box goes down until its top is aligned with the child.
if *margin_top < box.margin.get().top {
// TODO: The position of child floats should be updated and this
Expand All @@ -741,7 +741,7 @@ impl Flow for BlockFlow {
*margin_top = box.margin.get().top;
}
}
// The bottom margin of an in-flow block-level element collapses
// The bottom margin of an in-flow block-level element collapses
// with the top margin of its next in-flow block-level sibling.
*collapsing = geometry::min(box.margin.get().top, *collapsible);
*collapsible = box.margin.get().bottom;
Expand All @@ -760,7 +760,7 @@ impl Flow for BlockFlow {
} else {
let txt = if self.is_float() { ~"FloatFlow: " } else { ~"BlockFlow: " };
txt.append(match self.box {
Some(rb) => {
Some(ref rb) => {
rb.debug_str()
}
None => { ~"" }
Expand Down

5 comments on commit d26bf36

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from metajack
at ryanhc@d26bf36

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ryanhc/servo/owned_layout = d26bf36 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ryanhc/servo/owned_layout = d26bf36 merged ok, testing candidate = 794ea62

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 794ea62

Please sign in to comment.