auto merge of #1808 : pradeep90/servo/relative-position-container-block-size, r=pcwalton

This fixes #1757.
This commit is contained in:
bors-servo 2014-03-11 21:28:40 -04:00
commit af616dba58
5 changed files with 65 additions and 3 deletions

View file

@ -1279,6 +1279,7 @@ impl Box {
} }
/// TODO: What exactly does this function return? Why is it Au(0) for GenericBox?
pub fn content_width(&self) -> Au { pub fn content_width(&self) -> Au {
match self.specific { match self.specific {
GenericBox | IframeBox(_) => Au(0), GenericBox | IframeBox(_) => Au(0),
@ -1312,6 +1313,13 @@ impl Box {
} }
} }
/// Return the size of the content box.
pub fn content_box_size(&self) -> Size2D<Au> {
let border_box_size = self.border_box.get().size;
Size2D(border_box_size.width - self.noncontent_width(),
border_box_size.height - self.noncontent_height())
}
/// Split box which includes new-line character /// Split box which includes new-line character
pub fn split_by_new_line(&self) -> SplitBoxResult { pub fn split_by_new_line(&self) -> SplitBoxResult {
match self.specific { match self.specific {

View file

@ -957,9 +957,9 @@ impl<'a> MutableFlowUtils for &'a mut Flow {
// TODO(pradeep): Move this into a generated CB function and stuff in Flow. // TODO(pradeep): Move this into a generated CB function and stuff in Flow.
match block.box_ { match block.box_ {
Some(ref box_) => { Some(ref box_) => {
// FIXME: This should be the size of the content box (which is the // The Containing Block formed by a Block for relatively
// Containing Block formed by a BlockFlow), not the border box. // positioned descendants is the content box.
container_block_size = box_.border_box.get().size; container_block_size = box_.content_box_size();
abs_cb_position = if block.is_positioned() { abs_cb_position = if block.is_positioned() {
block.base.abs_position + block.generated_cb_position() block.base.abs_position + block.generated_cb_position()

View file

@ -52,3 +52,4 @@
== position_fixed_simple_a.html position_fixed_simple_b.html == position_fixed_simple_a.html position_fixed_simple_b.html
== position_fixed_static_y_a.html position_fixed_static_y_b.html == position_fixed_static_y_a.html position_fixed_static_y_b.html
== position_relative_a.html position_relative_b.html == position_relative_a.html position_relative_b.html
== position_relative_top_percentage_a.html position_relative_top_percentage_b.html

View file

@ -0,0 +1,25 @@
<html>
<head>
<style>
#first {
width: 100px;
height: 100px;
border: solid 10px;
}
#rel {
position: relative;
left: 50%;
top: 50%;
width: 50px;
height: 50px;
background: green;
}
</style>
</head>
<body>
<div id="first">
<div id="rel">
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,28 @@
<html>
<head>
<style>
#first {
width: 100px;
height: 100px;
border: solid 10px;
}
.box {
width: 50px;
height: 50px;
}
#green_square {
height: 50px;
width: 50px;
margin-left: 50px;
background: green;
}
</style>
</head>
<body>
<div id="first">
<div class="box"></div>
<div id="green_square">
</div>
</div>
</body>
</html>