LibWeb: Remove code duplication in computing height for abs-pos elements
This refactors the solve_for_{top, bottom, height, etc} lambdas to use a common solve_for lambda that takes the length to be solved as an argument. This way some code duplication is removed.
This commit is contained in:
parent
ca0a0b7a93
commit
8373a14835
Notes:
sideshowbarker
2024-07-17 06:01:26 +09:00
Author: https://github.com/FireFox317 Commit: https://github.com/SerenityOS/serenity/commit/8373a14835 Pull-request: https://github.com/SerenityOS/serenity/pull/15550
1 changed files with 14 additions and 52 deletions
|
@ -700,9 +700,10 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
auto height_of_containing_block = available_space.height.to_px();
|
||||
auto height_of_containing_block_as_length = CSS::Length::make_px(height_of_containing_block);
|
||||
|
||||
auto solve_for_top = [&] {
|
||||
top = CSS::Length::make_px(
|
||||
auto solve_for = [&](CSS::Length length) {
|
||||
return CSS::Length::make_px(
|
||||
height_of_containing_block
|
||||
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- margin_top.length().to_px(box)
|
||||
- box.computed_values().border_top().width
|
||||
- box.computed_values().padding().top().length().to_px(box)
|
||||
|
@ -710,71 +711,32 @@ void FormattingContext::compute_height_for_absolutely_positioned_non_replaced_el
|
|||
- box.computed_values().padding().bottom().length().to_px(box)
|
||||
- box.computed_values().border_bottom().width
|
||||
- margin_bottom.length().to_px(box)
|
||||
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box));
|
||||
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
+ length.to_px(box));
|
||||
};
|
||||
|
||||
auto solve_for_top = [&] {
|
||||
top = solve_for(top.resolved(box, height_of_containing_block_as_length));
|
||||
};
|
||||
|
||||
auto solve_for_bottom = [&] {
|
||||
bottom = CSS::Length::make_px(
|
||||
height_of_containing_block
|
||||
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- margin_top.length().to_px(box)
|
||||
- box.computed_values().border_top().width
|
||||
- box.computed_values().padding().top().length().to_px(box)
|
||||
- height.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().padding().bottom().length().to_px(box)
|
||||
- box.computed_values().border_bottom().width
|
||||
- margin_bottom.length().to_px(box));
|
||||
bottom = solve_for(bottom.resolved(box, height_of_containing_block_as_length));
|
||||
};
|
||||
|
||||
auto solve_for_height = [&] {
|
||||
height = CSS::Size::make_px(
|
||||
height_of_containing_block
|
||||
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- margin_top.length().to_px(box)
|
||||
- box.computed_values().border_top().width
|
||||
- box.computed_values().padding().top().length().to_px(box)
|
||||
- box.computed_values().padding().bottom().length().to_px(box)
|
||||
- box.computed_values().border_bottom().width
|
||||
- margin_bottom.length().to_px(box)
|
||||
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box));
|
||||
height = CSS::Size::make_length(solve_for(height.resolved(box, height_of_containing_block_as_length)));
|
||||
};
|
||||
|
||||
auto solve_for_margin_top = [&] {
|
||||
margin_top = CSS::Length::make_px(
|
||||
height_of_containing_block
|
||||
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().border_top().width
|
||||
- box.computed_values().padding().top().length().to_px(box)
|
||||
- height.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().padding().bottom().length().to_px(box)
|
||||
- box.computed_values().border_bottom().width
|
||||
- margin_bottom.length().to_px(box)
|
||||
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box));
|
||||
margin_top = solve_for(margin_top.length());
|
||||
};
|
||||
|
||||
auto solve_for_margin_bottom = [&] {
|
||||
margin_bottom = CSS::Length::make_px(
|
||||
height_of_containing_block
|
||||
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- margin_top.length().to_px(box)
|
||||
- box.computed_values().border_top().width
|
||||
- box.computed_values().padding().top().length().to_px(box)
|
||||
- height.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().padding().bottom().length().to_px(box)
|
||||
- box.computed_values().border_bottom().width
|
||||
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box));
|
||||
margin_bottom = solve_for(margin_bottom.length());
|
||||
};
|
||||
|
||||
auto solve_for_margin_top_and_margin_bottom = [&] {
|
||||
auto remainder = height_of_containing_block
|
||||
- top.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().border_top().width
|
||||
- box.computed_values().padding().top().length().to_px(box)
|
||||
- height.resolved(box, height_of_containing_block_as_length).to_px(box)
|
||||
- box.computed_values().padding().bottom().length().to_px(box)
|
||||
- box.computed_values().border_bottom().width
|
||||
- bottom.resolved(box, height_of_containing_block_as_length).to_px(box);
|
||||
|
||||
auto remainder = solve_for(CSS::Length::make_px(margin_top.length().to_px(box) + margin_bottom.length().to_px(box))).to_px(box);
|
||||
margin_top = CSS::Length::make_px(remainder / 2);
|
||||
margin_bottom = CSS::Length::make_px(remainder / 2);
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue