mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-28 13:43:45 +03:00
LibWeb: Saturate PixelUnits on creation when needed
This commit is contained in:
parent
95d00553c9
commit
1e5ba09d76
Notes:
sideshowbarker
2024-07-17 18:46:30 +09:00
Author: https://github.com/Hendiadyoin1 Commit: https://github.com/SerenityOS/serenity/commit/1e5ba09d76 Pull-request: https://github.com/SerenityOS/serenity/pull/20210 Reviewed-by: https://github.com/kalenikaliaksandr ✅
@ -11,17 +11,28 @@ namespace Web {
|
||||
|
||||
CSSPixels::CSSPixels(int value)
|
||||
{
|
||||
m_value = value * fixed_point_denominator;
|
||||
if (value > max_integer_value) [[unlikely]]
|
||||
m_value = NumericLimits<int>::max();
|
||||
else if (value < min_integer_value) [[unlikely]]
|
||||
m_value = NumericLimits<int>::min();
|
||||
else
|
||||
m_value = value << fractional_bits;
|
||||
}
|
||||
|
||||
CSSPixels::CSSPixels(unsigned int value)
|
||||
{
|
||||
m_value = value * fixed_point_denominator;
|
||||
if (value > max_integer_value) [[unlikely]]
|
||||
m_value = NumericLimits<int>::max();
|
||||
else
|
||||
m_value = static_cast<int>(value) << fractional_bits;
|
||||
}
|
||||
|
||||
CSSPixels::CSSPixels(unsigned long value)
|
||||
{
|
||||
m_value = value * fixed_point_denominator;
|
||||
if (value > max_integer_value) [[unlikely]]
|
||||
m_value = NumericLimits<int>::max();
|
||||
else
|
||||
m_value = static_cast<int>(value) << fractional_bits;
|
||||
}
|
||||
|
||||
CSSPixels::CSSPixels(float value)
|
||||
|
@ -57,6 +57,9 @@ public:
|
||||
|
||||
static constexpr i32 radix_mask = fixed_point_denominator - 1;
|
||||
|
||||
static constexpr i32 max_integer_value = NumericLimits<int>::max() >> fractional_bits;
|
||||
static constexpr i32 min_integer_value = NumericLimits<int>::min() >> fractional_bits;
|
||||
|
||||
CSSPixels() = default;
|
||||
CSSPixels(int value);
|
||||
CSSPixels(unsigned int value);
|
||||
|
Loading…
Reference in New Issue
Block a user