LibWeb: Only allow DevicePixels operators to work with integers

Allowing floats here was causing accidental truncations.

Co-authored-by: MacDue <macdue@dueutil.tech>
This commit is contained in:
Sam Atkins 2022-12-14 10:52:29 +00:00 committed by Linus Groh
parent d3cdf151a4
commit a3298017d6
Notes: sideshowbarker 2024-07-17 03:13:05 +09:00

View file

@ -17,33 +17,33 @@ namespace Web {
/// DevicePixels: A position or length on the physical display.
AK_TYPEDEF_DISTINCT_NUMERIC_GENERAL(int, DevicePixels, Arithmetic, CastToUnderlying, Comparison, Increment);
template<Arithmetic T>
template<Integral T>
constexpr bool operator==(DevicePixels left, T right) { return left.value() == right; }
template<Arithmetic T>
template<Integral T>
constexpr bool operator!=(DevicePixels left, T right) { return left.value() != right; }
template<Arithmetic T>
template<Integral T>
constexpr bool operator>(DevicePixels left, T right) { return left.value() > right; }
template<Arithmetic T>
template<Integral T>
constexpr bool operator<(DevicePixels left, T right) { return left.value() < right; }
template<Arithmetic T>
template<Integral T>
constexpr bool operator>=(DevicePixels left, T right) { return left.value() >= right; }
template<Arithmetic T>
template<Integral T>
constexpr bool operator<=(DevicePixels left, T right) { return left.value() <= right; }
template<Arithmetic T>
template<Integral T>
constexpr DevicePixels operator*(DevicePixels left, T right) { return left.value() * right; }
template<Arithmetic T>
template<Integral T>
constexpr DevicePixels operator*(T left, DevicePixels right) { return right * left; }
template<Arithmetic T>
template<Integral T>
constexpr DevicePixels operator/(DevicePixels left, T right) { return left.value() / right; }
template<Arithmetic T>
template<Integral T>
constexpr DevicePixels operator%(DevicePixels left, T right) { return left.value() % right; }
/// CSSPixels: A position or length in CSS "reference pixels", independent of zoom or screen DPI.