mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
LibWeb: Clamp CSS z-index to the range of a 32-bit integer
This appears to be consistent with other engines, and fixes many pages where we were misinterpreting super large z-index values as something else entirely.
This commit is contained in:
parent
cead039e7e
commit
7465362fe7
Notes:
sideshowbarker
2024-07-17 06:24:08 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/7465362fe7 Pull-request: https://github.com/SerenityOS/serenity/pull/18514
1 changed files with 10 additions and 2 deletions
|
@ -216,8 +216,16 @@ Optional<int> StyleProperties::z_index() const
|
|||
auto value = property(CSS::PropertyID::ZIndex);
|
||||
if (value->has_auto())
|
||||
return {};
|
||||
if (value->has_integer())
|
||||
return value->to_integer();
|
||||
if (value->has_integer()) {
|
||||
// Clamp z-index to the range of a signed 32-bit integer for consistency with other engines.
|
||||
// NOTE: Casting between 32-bit float and 32-bit integer is finicky here, since INT32_MAX is not representable as a 32-bit float!
|
||||
auto integer = value->to_integer();
|
||||
if (integer >= static_cast<float>(NumericLimits<int>::max()))
|
||||
return NumericLimits<int>::max();
|
||||
if (integer <= static_cast<float>(NumericLimits<int>::min()))
|
||||
return NumericLimits<int>::min();
|
||||
return static_cast<int>(integer);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue