Skip to content

Commit

Permalink
Fix float placement bugs & add hacky non-percen heights to blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Atkinson committed Jul 12, 2013
1 parent 650bd65 commit 602334a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
21 changes: 15 additions & 6 deletions src/components/main/layout/block.rs
Expand Up @@ -249,12 +249,14 @@ impl BlockFlowData {
pub fn assign_height_block(@mut self, ctx: &mut LayoutContext) {
let mut cur_y = Au(0);
let mut top_offset = Au(0);
let mut bottom_offset = Au(0);
let mut left_offset = Au(0);

for self.box.iter().advance |&box| {
do box.with_model |model| {
top_offset = model.margin.top + model.border.top + model.padding.top;
cur_y = cur_y + top_offset;
bottom_offset = model.margin.bottom + model.border.bottom + model.padding.bottom;
left_offset = model.offset();
};
}
Expand All @@ -277,7 +279,7 @@ impl BlockFlowData {
}
kid.assign_height(ctx);
do kid.with_mut_base |child_node| {
float_ctx = child_node.floats_out.translate(Point2D(Au(0), -child_node.position.size.height));
float_ctx = child_node.floats_out.clone();
}

}
Expand All @@ -288,12 +290,19 @@ impl BlockFlowData {
};
}

let height = if self.is_root {
let mut height = if self.is_root {
Au::max(ctx.screen_size.size.height, cur_y)
} else {
cur_y - top_offset
cur_y - top_offset
};


for self.box.each |&box| {
let style = box.style();
let maybe_height = MaybeAuto::from_height(style.height(), Au(0));
let maybe_height = maybe_height.spec_or_default(Au(0));
height = geometry::max(height, maybe_height);
}

let mut noncontent_height = Au(0);
self.box.map(|&box| {
do box.with_mut_base |base| {
Expand All @@ -311,8 +320,8 @@ impl BlockFlowData {
//TODO(eatkinson): compute heights using the 'height' property.
self.common.position.size.height = height + noncontent_height;


self.common.floats_out = float_ctx.translate(Point2D(left_offset, self.common.position.size.height));
let extra_height = height - (cur_y - top_offset) + bottom_offset;
self.common.floats_out = float_ctx.translate(Point2D(left_offset, -extra_height));
}

pub fn build_display_list_block<E:ExtraDisplayListData>(@mut self,
Expand Down
2 changes: 1 addition & 1 deletion src/components/main/layout/float.rs
Expand Up @@ -8,7 +8,7 @@ use layout::display_list_builder::{DisplayListBuilder, ExtraDisplayListData};
use layout::display_list_builder::{FlowDisplayListBuilderMethods};
use layout::flow::{FloatFlow, FlowData};
use layout::model::{MaybeAuto};
use layout::float_context::{FloatContext, PlacementInfo, FloatLeft, FloatType};
use layout::float_context::{FloatContext, PlacementInfo, FloatType};

use std::cell::Cell;
use geom::point::Point2D;
Expand Down
14 changes: 6 additions & 8 deletions src/components/main/layout/float_context.rs
Expand Up @@ -196,14 +196,12 @@ impl FloatContextBase{
_ => fail!("Reached unreachable state when computing float area")
};

// When the window is smaller than the float, we will return a rect
// with negative width.
assert!(max_left < min_right
|| max_left > max_x - self.offset.x
|| min_right < Au(0) - self.offset.x
,"Float position error");

//TODO(eatkinson): do we need to do something similar for heights?
// This assertion is too strong and fails in some cases. It is OK to
// return negative widths since we check against that right away, but
// we should still undersrtand why they occur and add a stronger
// assertion here.
//assert!(max_left < min_right);

assert!(top < bottom, "Float position error");

Some(Rect{
Expand Down

0 comments on commit 602334a

Please sign in to comment.