Skip to content

Commit

Permalink
Position the background image on the padding box.
Browse files Browse the repository at this point in the history
According to CSS2.1 spec, background image should be positioned on padding box.
Spec: http://www.w3.org/TR/CSS21/colors.html#propdef-background-position

Fixes #6034.
  • Loading branch information
Jinwoo-Song committed May 13, 2015
1 parent b3b9dea commit 7283f75
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/layout/display_list_builder.rs
Expand Up @@ -435,8 +435,11 @@ impl FragmentDisplayListBuilding for Fragment {
let vertical_position = model::specified(background.background_position.vertical,
bounds.size.height - image_size.height);

let abs_x = virtual_origin_x + horizontal_position;
let abs_y = virtual_origin_y + vertical_position;
// Background image should be positioned on the padding box basis.
let border = style.logical_border_width().to_physical(style.writing_mode);

let abs_x = border.left + virtual_origin_x + horizontal_position;
let abs_y = border.top + virtual_origin_y + vertical_position;

// Adjust origin and size based on background-repeat
match background.background_repeat {
Expand Down
22 changes: 22 additions & 0 deletions tests/ref/background_image_a.html
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
background-image: url("test.jpeg");
width: 420px;
height: 298px;
border-width: 10px 20px 30px 40px;
border-style: solid;
border-color: red;
padding: 40px;
}
</style>
</head>
<body>

<div></div>

</body>
</html>

22 changes: 22 additions & 0 deletions tests/ref/background_image_ref.html
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 560px;
height: 418px;
background-color: red;
}

</style>
</head>
<body>

<div>
<!-- Image dimension is 500x378. -->
<img src="test.jpeg" style="position:relative; left:40px; top:10px;">
</div>

</body>
</html>

0 comments on commit 7283f75

Please sign in to comment.