summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-12-14 10:52:29 +0000
committerLinus Groh <mail@linusgroh.de>2022-12-14 16:47:57 +0000
commita3298017d6d70da15f172ddeb6241b749f8eb5ff (patch)
treeb09c0b643f7e9137d66d10a323d99c095a753504
parentd3cdf151a4e737d407f8a499b45a720de0018675 (diff)
downloadserenity-a3298017d6d70da15f172ddeb6241b749f8eb5ff.zip
LibWeb: Only allow DevicePixels operators to work with integers
Allowing floats here was causing accidental truncations. Co-authored-by: MacDue <macdue@dueutil.tech>
-rw-r--r--Userland/Libraries/LibWeb/PixelUnits.h20
1 files changed, 10 insertions, 10 deletions
diff --git a/Userland/Libraries/LibWeb/PixelUnits.h b/Userland/Libraries/LibWeb/PixelUnits.h
index 702107e81b..0e99009c76 100644
--- a/Userland/Libraries/LibWeb/PixelUnits.h
+++ b/Userland/Libraries/LibWeb/PixelUnits.h
@@ -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.