mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibWeb: Add Length::resolved()
overload for CSSPixels
Since we always pass the px value as an argument to resolved(), we can pass it directly as CSSPixels instead of wrapping it in Length. This approach allows us to avoid converting to a double, resulting in fewer precision issues.
This commit is contained in:
parent
5eb0f65cc0
commit
0fb571c1c2
Notes:
sideshowbarker
2024-07-17 08:43:11 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 0fb571c1c2
Pull-request: https://github.com/SerenityOS/serenity/pull/20839
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/awesomekling
14 changed files with 154 additions and 75 deletions
|
@ -2338,6 +2338,22 @@ Optional<Length> CalculatedStyleValue::resolve_length_percentage(Layout::Node co
|
|||
});
|
||||
}
|
||||
|
||||
Optional<Length> CalculatedStyleValue::resolve_length_percentage(Layout::Node const& layout_node, CSSPixels percentage_basis) const
|
||||
{
|
||||
auto result = m_calculation->resolve(Length::ResolutionContext::for_layout_node(layout_node), Length::make_px(percentage_basis));
|
||||
|
||||
return result.value().visit(
|
||||
[&](Length const& length) -> Optional<Length> {
|
||||
return length;
|
||||
},
|
||||
[&](Percentage const& percentage) -> Optional<Length> {
|
||||
return Length::make_px(CSSPixels(percentage.value() * percentage_basis) / 100);
|
||||
},
|
||||
[&](auto const&) -> Optional<Length> {
|
||||
return {};
|
||||
});
|
||||
}
|
||||
|
||||
Optional<Percentage> CalculatedStyleValue::resolve_percentage() const
|
||||
{
|
||||
auto result = m_calculation->resolve({}, {});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue