LibWeb/CSS: Treat x resolution unit separately from dppx

Tests show that we need to preserve whether x or dppx units were used,
so the simplest way is to treat them separately.
This commit is contained in:
Sam Atkins 2025-05-16 20:15:07 +01:00 committed by Tim Ledbetter
commit 338282f74d
Notes: github-actions[bot] 2025-05-17 06:54:37 +00:00
3 changed files with 14 additions and 9 deletions

View file

@ -35,6 +35,7 @@ double Resolution::to_dots_per_pixel() const
case Type::Dpcm: case Type::Dpcm:
return m_value / (96.0 / 2.54); // 1cm = 96px/2.54 return m_value / (96.0 / 2.54); // 1cm = 96px/2.54
case Type::Dppx: case Type::Dppx:
case Type::X:
return m_value; return m_value;
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
@ -49,19 +50,22 @@ StringView Resolution::unit_name() const
return "dpcm"sv; return "dpcm"sv;
case Type::Dppx: case Type::Dppx:
return "dppx"sv; return "dppx"sv;
case Type::X:
return "x"sv;
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
} }
Optional<Resolution::Type> Resolution::unit_from_name(StringView name) Optional<Resolution::Type> Resolution::unit_from_name(StringView name)
{ {
if (name.equals_ignoring_ascii_case("dpi"sv)) { if (name.equals_ignoring_ascii_case("dpi"sv))
return Type::Dpi; return Type::Dpi;
} else if (name.equals_ignoring_ascii_case("dpcm"sv)) { if (name.equals_ignoring_ascii_case("dpcm"sv))
return Type::Dpcm; return Type::Dpcm;
} else if (name.equals_ignoring_ascii_case("dppx"sv) || name.equals_ignoring_ascii_case("x"sv)) { if (name.equals_ignoring_ascii_case("dppx"sv))
return Type::Dppx; return Type::Dppx;
} if (name.equals_ignoring_ascii_case("x"sv))
return Type::X;
return {}; return {};
} }

View file

@ -17,6 +17,7 @@ public:
Dpi, Dpi,
Dpcm, Dpcm,
Dppx, Dppx,
X,
}; };
static Optional<Type> unit_from_name(StringView); static Optional<Type> unit_from_name(StringView);

View file

@ -2,8 +2,8 @@ Harness status: OK
Found 34 tests Found 34 tests
27 Pass 30 Pass
7 Fail 4 Fail
Pass Test parsing '' with matchMedia Pass Test parsing '' with matchMedia
Pass Test parsing ' ' with matchMedia Pass Test parsing ' ' with matchMedia
Pass Test parsing 'all' with matchMedia Pass Test parsing 'all' with matchMedia
@ -25,11 +25,11 @@ Pass Test parsing ' , ' with matchMedia
Fail Test parsing ',,' with matchMedia Fail Test parsing ',,' with matchMedia
Pass Test parsing ' , , ' with matchMedia Pass Test parsing ' , , ' with matchMedia
Fail Test parsing ' foo,' with matchMedia Fail Test parsing ' foo,' with matchMedia
Fail Test parsing '(min-resolution: 1x)' with matchMedia Pass Test parsing '(min-resolution: 1x)' with matchMedia
Pass Test parsing '(min-resolution: calc(1x))' with matchMedia Pass Test parsing '(min-resolution: calc(1x))' with matchMedia
Fail Test parsing '(resolution: 2x)' with matchMedia Pass Test parsing '(resolution: 2x)' with matchMedia
Pass Test parsing '(resolution: calc(2x))' with matchMedia Pass Test parsing '(resolution: calc(2x))' with matchMedia
Fail Test parsing '(max-resolution: 7x)' with matchMedia Pass Test parsing '(max-resolution: 7x)' with matchMedia
Pass Test parsing '(max-resolution: calc(7x))' with matchMedia Pass Test parsing '(max-resolution: calc(7x))' with matchMedia
Pass Test parsing '(resolution: 2dppx)' with matchMedia Pass Test parsing '(resolution: 2dppx)' with matchMedia
Pass Test parsing '(resolution: 600dpi)' with matchMedia Pass Test parsing '(resolution: 600dpi)' with matchMedia