mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibWeb: Set margin, padding and border for replaced boxes
Separating the paths for replaced and non-replaced floating boxes lost the logic for margin, padding and border which was done by compute_width_for_floating_box. Set them the same way as we do for block-level replaced elements, per the specification.
This commit is contained in:
parent
e48074e401
commit
7f9ede07bc
3 changed files with 66 additions and 1 deletions
16
Tests/LibWeb/Layout/expected/set-margin-of-floating-box.txt
Normal file
16
Tests/LibWeb/Layout/expected/set-margin-of-floating-box.txt
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
|
BlockContainer <html> at (0,0) content-size 800x116 [BFC] children: not-inline
|
||||||
|
BlockContainer <(anonymous)> at (0,0) content-size 800x0 children: inline
|
||||||
|
TextNode <#text>
|
||||||
|
BlockContainer <body> at (8,16) content-size 784x17.46875 children: not-inline
|
||||||
|
BlockContainer <(anonymous)> at (8,16) content-size 784x0 children: inline
|
||||||
|
TextNode <#text>
|
||||||
|
ImageBox <img> at (8,16) content-size 200x100 floating children: not-inline
|
||||||
|
TextNode <#text>
|
||||||
|
BlockContainer <p> at (8,16) content-size 784x17.46875 children: inline
|
||||||
|
line 0 width: 37.21875, height: 17.46875, bottom: 17.46875, baseline: 13.53125
|
||||||
|
frag 0 from TextNode start: 0, length: 4, rect: [228,16 37.21875x17.46875]
|
||||||
|
"Test"
|
||||||
|
TextNode <#text>
|
||||||
|
BlockContainer <(anonymous)> at (8,49.46875) content-size 784x0 children: inline
|
||||||
|
TextNode <#text>
|
19
Tests/LibWeb/Layout/input/set-margin-of-floating-box.html
Normal file
19
Tests/LibWeb/Layout/input/set-margin-of-floating-box.html
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
img {
|
||||||
|
width: 200px;
|
||||||
|
float: left;
|
||||||
|
margin: 0 20px 0 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<img
|
||||||
|
src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABLAAAAJYCAMAAABFOO8oAAABg1BMVEUAAAAXK0wXK00YJTwYLlEYLlIYLlQYMloYMlwYNmMZAAAZIjYZIzgZJDkZJj8ZLVEZMVkZQHcaNmQaOmsbMVQcJzwcNVsdPW4eK0QfNVYfNlwfQ3kfRXofR38gQHAhOF4hOWAiIiIiJCwiJS4iJi8iJzEiRnwjJy4jKz4jLEIjXK8jXLAkKjUkLDEkP2kkR3wkSIAkXbIkX7UkX7YlSYAlYLclYbkmMEYmSn0mYrwmZL8nZcEnZsInZsMoS30pZ8MqaMQracQva8UvbMUybsYzbsY0b8c1cMc2ccc5hwU6c8g6dMg6hwU7dMk7iQU7igU8dck8jQU9dslAlgZKlxVShc9Thc9YidFYzwha0ghbZH1b1Qhd2QleZ4Je3Qlf3glg4glh5Ali5gljkdRkkdRlbIdm5xBpcIhy6SJ00zR1ndl4n9p42jZ95Th/pNyB6zqDp92Q3luRseCY6mCb72Khq9KrsNGrsdOsstOts9OvtNOv8oK3AAC4vNi9wdu/w9zJAAAM9N5KAAAKzElEQVR42u3dzWscdRjA8Y1pG7EGtW9Ei6XRpj2poEfRWz0J6qGgBxHyJ3jw1EMOPfWP6FUErV60J0HISbEFWxQ1h0ix9gVtxaQx6TaJwjy/wvyc2c2msbuZ/XwuD7O72axZ+XYODzMjky2A7eEhfwJAsAAECxAsAMECECxAsAAEC0CwAMECECwAwQIEC0CwAAQLECwAwQIQLECwAAQLQLAAwQIQLADBAgQLQLAABAsQLADBAgQLQLAABAsQLADBAhAsQLAABAtAsADBAhAsAMECBAtAsAAECxAsAMECECxAsAAEC0CwAMECECwAwQIEC0CwAAQLECwAwQIEC0CwAAQLECwAwQIQLECwAAQLQLAAwQIQLADBAgQLQLAABAsQLADBAhAsQLAABAtAsADBAhAsAMECBAtAsAAECxAsAMECBAtAsAAEC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Zs3+Vf5wfrmZWLSajcMTMffHvFT9rj/FbMdM9/N6rvNn/SSm/StnWACCBSBYgGABCBaAYAGCBTBQ7GENj5nSqN2/yhatul0ea7Z8eC17eiJmLF5NxuGfMeO2Xv+5j1fms5jPxLzj23SGBSBYAIIFCBaAYAEIFiBYAINkZNLfYFjMlw/rFqxq9rDy62BNV//0zzFXY6aNqeVirHf5jNk+1tmYk9m74QwLQLAABAsQLADBAhAsQLAABoo9rKFzPWa6XWGXC16dqnn8vZixcLVePrzn4sY+VNq/WizGuTh0/0GcYQGCBSBYAIIFCBaAYAGCBbAt2MMaWvO9vfydmB9WP/325j5E7F21voh5tBgrvh6cYQGCBSBYAIIFCBaAYAG0rDWw4f9TYqar07wWc60Y6bIy+eVlRsvz8zgci/lkzY+BMyxAsAAEC0CwAMECECwAwQK2E3tYgDMsAMECBAtAsAAECxAsAMECECxAsAAEC0CwAMECECwAwQIEC0CwAAQLECwAwQIQLECwAAQLQLAAwQIQLADBAgQLQLAAwfInAAQLQLAAwQIQLADBAgQLQLAABAsQLADBAhAsQLAABAtAsADBAhAsAMECBAtAsAAECxAsAMECECxAsAAEC0CwAMECECxAsAAEC0CwAMECECwAwQIEC0CwAAQLECwAwQIQLECwAAQLQLAAwQIQLADBAgQLQLAABAsQLADBAhAsQLAABAtAsADBAhAsQLAABAtAsADBAhAsAMECBAtAsAAECxAsAMECECxAsAAEC0CwAMECECwAwQIEC0CwAAQLECwAwQIQLECwAAQLQLAAwQIQLECwAAQLQLAAwQIQLADBAgQLQLAABAsQLADBAhAsQLAABAtAsADBAhAsAMECBAtAsAAECxAsAMECECxAsAAEC0CwAMECECxAsAAEC0CwAMECECwAwQIEC0CwAAQLECwAwQIQLECwAAQLQLAAwQIQLADBAgQLQLAABAsQLADBAhAsQLAABAtAsADBAhAsQLAABAtAsADBAhAsAMECBAtAsAAEC2i8fwDFkO6lWFprKQAAAABJRU5ErkJggg==">
|
||||||
|
<p>Test</p>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
|
@ -352,7 +352,37 @@ void BlockFormattingContext::compute_width_for_floating_box(Box const& box, Avai
|
||||||
|
|
||||||
void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_normal_flow(ReplacedBox const& box, AvailableSpace const& available_space)
|
void BlockFormattingContext::compute_width_for_block_level_replaced_element_in_normal_flow(ReplacedBox const& box, AvailableSpace const& available_space)
|
||||||
{
|
{
|
||||||
m_state.get_mutable(box).set_content_width(compute_width_for_replaced_element(m_state, box, available_space));
|
// 10.3.6 Floating, replaced elements
|
||||||
|
auto& computed_values = box.computed_values();
|
||||||
|
|
||||||
|
auto zero_value = CSS::Length::make_px(0);
|
||||||
|
auto width_of_containing_block = available_space.width.to_px();
|
||||||
|
auto width_of_containing_block_as_length_for_resolve = CSS::Length::make_px(width_of_containing_block);
|
||||||
|
if (!available_space.width.is_definite())
|
||||||
|
width_of_containing_block_as_length_for_resolve = CSS::Length::make_px(0);
|
||||||
|
|
||||||
|
// 10.3.4 Block-level, replaced elements in normal flow
|
||||||
|
// The used value of 'width' is determined as for inline replaced elements. Then the rules for
|
||||||
|
// non-replaced block-level elements are applied to determine the margins.
|
||||||
|
auto margin_left = computed_values.margin().left().resolved(box, width_of_containing_block_as_length_for_resolve);
|
||||||
|
auto margin_right = computed_values.margin().right().resolved(box, width_of_containing_block_as_length_for_resolve);
|
||||||
|
auto const padding_left = computed_values.padding().left().to_px(box, width_of_containing_block);
|
||||||
|
auto const padding_right = computed_values.padding().right().to_px(box, width_of_containing_block);
|
||||||
|
|
||||||
|
// If 'margin-left', or 'margin-right' are computed as 'auto', their used value is '0'.
|
||||||
|
if (margin_left.is_auto())
|
||||||
|
margin_left = zero_value;
|
||||||
|
if (margin_right.is_auto())
|
||||||
|
margin_right = zero_value;
|
||||||
|
|
||||||
|
auto& box_state = m_state.get_mutable(box);
|
||||||
|
box_state.set_content_width(compute_width_for_replaced_element(m_state, box, available_space));
|
||||||
|
box_state.margin_left = margin_left.to_px(box);
|
||||||
|
box_state.margin_right = margin_right.to_px(box);
|
||||||
|
box_state.border_left = computed_values.border_left().width;
|
||||||
|
box_state.border_right = computed_values.border_right().width;
|
||||||
|
box_state.padding_left = padding_left;
|
||||||
|
box_state.padding_right = padding_right;
|
||||||
}
|
}
|
||||||
|
|
||||||
CSSPixels BlockFormattingContext::compute_table_box_width_inside_table_wrapper(Box const& box, AvailableSpace const& available_space)
|
CSSPixels BlockFormattingContext::compute_table_box_width_inside_table_wrapper(Box const& box, AvailableSpace const& available_space)
|
||||||
|
|
Loading…
Add table
Reference in a new issue