mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibWeb/CSS: Resolve percentages in NumericCalculationNode
Percentages should be resolved against the provided percentage basis instead of just returning the underlying value. Fixes https://github.com/SerenityOS/serenity/issues/22654
This commit is contained in:
parent
5e7e98cd3c
commit
3f52d6045a
3 changed files with 33 additions and 1 deletions
|
@ -0,0 +1,9 @@
|
||||||
|
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
|
||||||
|
BlockContainer <html> at (0,0) content-size 800x116 [BFC] children: not-inline
|
||||||
|
BlockContainer <body> at (8,8) content-size 500x100 children: not-inline
|
||||||
|
BlockContainer <div> at (8,8) content-size 100x100 children: not-inline
|
||||||
|
|
||||||
|
ViewportPaintable (Viewport<#document>) [0,0 800x600]
|
||||||
|
PaintableWithLines (BlockContainer<HTML>) [0,0 800x116]
|
||||||
|
PaintableWithLines (BlockContainer<BODY>) [8,8 500x100]
|
||||||
|
PaintableWithLines (BlockContainer<DIV>) [8,8 100x100]
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!doctype html><style>
|
||||||
|
* {
|
||||||
|
outline: 1px solid black;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
width: 500px;
|
||||||
|
}
|
||||||
|
div {
|
||||||
|
width: min(100px, 50%);
|
||||||
|
height: 100px;
|
||||||
|
background: orange;
|
||||||
|
}
|
||||||
|
</style><body><div>
|
|
@ -217,8 +217,18 @@ bool NumericCalculationNode::contains_percentage() const
|
||||||
return m_value.has<Percentage>();
|
return m_value.has<Percentage>();
|
||||||
}
|
}
|
||||||
|
|
||||||
CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional<Length::ResolutionContext const&>, CalculatedStyleValue::PercentageBasis const&) const
|
CalculatedStyleValue::CalculationResult NumericCalculationNode::resolve(Optional<Length::ResolutionContext const&>, CalculatedStyleValue::PercentageBasis const& percentage_basis) const
|
||||||
{
|
{
|
||||||
|
if (m_value.has<Percentage>()) {
|
||||||
|
return percentage_basis.visit(
|
||||||
|
[&](Empty const&) -> CalculatedStyleValue::CalculationResult {
|
||||||
|
VERIFY_NOT_REACHED();
|
||||||
|
},
|
||||||
|
[&](auto const& value) {
|
||||||
|
return CalculatedStyleValue::CalculationResult(value.percentage_of(m_value.get<Percentage>()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return m_value;
|
return m_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue