LibWeb: Use document's viewport when resolving lengths in media queries

Previously we would always use the window's viewport which was incorrect
if we were within an iframe.

This is likely applicable to all uses of
`Length::ResolutionContext::for_window`.
This commit is contained in:
Callum Law 2025-10-07 00:54:19 +13:00 committed by Sam Atkins
commit 05c336ea4e
Notes: github-actions[bot] 2025-10-07 09:34:36 +00:00
23 changed files with 198 additions and 83 deletions

View file

@ -9,9 +9,9 @@
namespace Web::CSS {
bool BooleanExpression::evaluate_to_boolean(HTML::Window const* window) const
bool BooleanExpression::evaluate_to_boolean(DOM::Document const* document) const
{
return evaluate(window) == MatchResult::True;
return evaluate(document) == MatchResult::True;
}
void BooleanExpression::indent(StringBuilder& builder, int levels)
@ -25,11 +25,11 @@ void GeneralEnclosed::dump(StringBuilder& builder, int indent_levels) const
builder.appendff("GeneralEnclosed: {}\n", to_string());
}
MatchResult BooleanNotExpression::evaluate(HTML::Window const* window) const
MatchResult BooleanNotExpression::evaluate(DOM::Document const* document) const
{
// https://drafts.csswg.org/css-values-5/#boolean-logic
// `not test` evaluates to true if its contained test is false, false if its true, and unknown if its unknown.
switch (m_child->evaluate(window)) {
switch (m_child->evaluate(document)) {
case MatchResult::False:
return MatchResult::True;
case MatchResult::True:
@ -52,9 +52,9 @@ void BooleanNotExpression::dump(StringBuilder& builder, int indent_levels) const
m_child->dump(builder, indent_levels + 1);
}
MatchResult BooleanExpressionInParens::evaluate(HTML::Window const* window) const
MatchResult BooleanExpressionInParens::evaluate(DOM::Document const* document) const
{
return m_child->evaluate(window);
return m_child->evaluate(document);
}
String BooleanExpressionInParens::to_string() const
@ -71,14 +71,14 @@ void BooleanExpressionInParens::dump(StringBuilder& builder, int indent_levels)
builder.append(")\n"sv);
}
MatchResult BooleanAndExpression::evaluate(HTML::Window const* window) const
MatchResult BooleanAndExpression::evaluate(DOM::Document const* document) const
{
// https://drafts.csswg.org/css-values-5/#boolean-logic
// Multiple tests connected with `and` evaluate to true if all of those tests are true, false if any of them are
// false, and unknown otherwise (i.e. if at least one unknown, but no false).
size_t true_results = 0;
for (auto const& child : m_children) {
auto child_match = child->evaluate(window);
auto child_match = child->evaluate(document);
if (child_match == MatchResult::False)
return MatchResult::False;
if (child_match == MatchResult::True)
@ -102,14 +102,14 @@ void BooleanAndExpression::dump(StringBuilder& builder, int indent_levels) const
child->dump(builder, indent_levels + 1);
}
MatchResult BooleanOrExpression::evaluate(HTML::Window const* window) const
MatchResult BooleanOrExpression::evaluate(DOM::Document const* document) const
{
// https://drafts.csswg.org/css-values-5/#boolean-logic
// Multiple tests connected with `or` evaluate to true if any of those tests are true, false if all of them are
// false, and unknown otherwise (i.e. at least one unknown, but no true).
size_t false_results = 0;
for (auto const& child : m_children) {
auto child_match = child->evaluate(window);
auto child_match = child->evaluate(document);
if (child_match == MatchResult::True)
return MatchResult::True;
if (child_match == MatchResult::False)