Skip to content

Commit c197fb4

Browse files
committed
LibWeb: Take box-sizing into account when sizing replaced elements
This fixes an issue where images with padding and/or border did not have their size adjusted for `border-box`, thereby becoming larger than intended by the author.
1 parent 9531abc commit c197fb4

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (0,0) content-size 800x116 [BFC] children: not-inline
3+
BlockContainer <body> at (8,8) content-size 784x100 children: inline
4+
line 0 width: 200, height: 100, bottom: 100, baseline: 100
5+
frag 0 from ImageBox start: 0, length: 0, rect: [29,29 58x58]
6+
frag 1 from ImageBox start: 0, length: 0, rect: [129,29 58x58]
7+
ImageBox <img.with-height> at (29,29) content-size 58x58 children: not-inline
8+
ImageBox <img.with-width> at (129,29) content-size 58x58 children: not-inline
9+
TextNode <#text>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html><style>
2+
img {
3+
padding: 20px;
4+
box-sizing: border-box;
5+
border: 1px solid black;
6+
}
7+
.with-height {
8+
height: 100px;
9+
}
10+
.with-width {
11+
width: 100px;
12+
}
13+
</style><img class="with-height" src="120.png"><img class="with-width" src="120.png">

Userland/Libraries/LibWeb/Layout/FormattingContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ CSSPixels FormattingContext::tentative_width_for_replaced_element(ReplacedBox co
374374
auto height_of_containing_block = CSS::Length::make_px(containing_block_height_for(box));
375375
auto computed_height = should_treat_height_as_auto(box, available_space) ? CSS::Size::make_auto() : box.computed_values().height();
376376

377-
CSSPixels used_width = computed_width.to_px(box, available_space.width.to_px());
377+
CSSPixels used_width = calculate_inner_width(box, available_space.width, computed_width).to_px(box);
378378

379379
// If 'height' and 'width' both have computed values of 'auto' and the element also has an intrinsic width,
380380
// then that intrinsic width is the used value of 'width'.
@@ -497,7 +497,7 @@ CSSPixels FormattingContext::tentative_height_for_replaced_element(ReplacedBox c
497497
return 150;
498498

499499
// FIXME: Handle cases when available_space is not definite.
500-
return computed_height.to_px(box, available_space.height.to_px_or_zero());
500+
return calculate_inner_height(box, available_space.height, computed_height).to_px(box);
501501
}
502502

503503
CSSPixels FormattingContext::compute_height_for_replaced_element(ReplacedBox const& box, AvailableSpace const& available_space) const

0 commit comments

Comments
 (0)