Skip to content

Commit

Permalink
Send in the right container block size for relative positioning.
Browse files Browse the repository at this point in the history
This fixes #1757.
  • Loading branch information
pradeep90 committed Mar 4, 2014
1 parent 4a6077c commit 20a4ac6
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/components/main/layout/box_.rs
Expand Up @@ -1267,6 +1267,7 @@ impl Box {
}


/// TODO: What exactly does this function return? Why is it Au(0) for GenericBox?
pub fn content_width(&self) -> Au {
match self.specific {
GenericBox | IframeBox(_) => Au(0),
Expand Down Expand Up @@ -1300,6 +1301,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
pub fn split_by_new_line(&self) -> SplitBoxResult {
match self.specific {
Expand Down
6 changes: 3 additions & 3 deletions src/components/main/layout/flow.rs
Expand Up @@ -957,9 +957,9 @@ impl<'a> MutableFlowUtils for &'a mut Flow {
// TODO(pradeep): Move this into a generated CB function and stuff in Flow.
match block.box_ {
Some(ref box_) => {
// FIXME: This should be the size of the content box (which is the
// Containing Block formed by a BlockFlow), not the border box.
container_block_size = box_.border_box.get().size;
// The Containing Block formed by a Block for relatively
// positioned descendants is the content box.
container_block_size = box_.content_box_size();

abs_cb_position = if block.is_positioned() {
block.base.abs_position + block.generated_cb_position()
Expand Down
1 change: 1 addition & 0 deletions src/test/ref/basic.list
Expand Up @@ -44,3 +44,4 @@
== position_fixed_simple_a.html position_fixed_simple_b.html
== position_fixed_static_y_a.html position_fixed_static_y_b.html
== position_relative_a.html position_relative_b.html
== position_relative_top_percentage_a.html position_relative_top_percentage_b.html
25 changes: 25 additions & 0 deletions src/test/ref/position_relative_top_percentage_a.html
@@ -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>
28 changes: 28 additions & 0 deletions src/test/ref/position_relative_top_percentage_b.html
@@ -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>

9 comments on commit 20a4ac6

@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 pcwalton
at pradeep90@20a4ac6

@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 pradeep90/servo/relative-position-container-block-size = 20a4ac6 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.

pradeep90/servo/relative-position-container-block-size = 20a4ac6 merged ok, testing candidate = fadf2b0

@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.

saw approval from pcwalton
at pradeep90@20a4ac6

@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 pradeep90/servo/relative-position-container-block-size = 20a4ac6 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.

pradeep90/servo/relative-position-container-block-size = 20a4ac6 merged ok, testing candidate = af616db

@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 = af616db

Please sign in to comment.