mirror of
https://github.com/RGBCube/serenity
synced 2025-05-20 14:55:08 +00:00
LibWeb: Add CSSPixels::nearest_value_for(FloatingPoint)
This is intended to annotate conversions from unknown floating-point values to CSSPixels, and make it more obvious the fp value will be rounded to the nearest fixed-point value.
This commit is contained in:
parent
360c0eb509
commit
71baa8c31a
28 changed files with 120 additions and 112 deletions
|
@ -3993,14 +3993,14 @@ static RefPtr<CSS::StyleValue> parse_current_dimension_value(float value, Utf8Vi
|
|||
{
|
||||
// 1. If position is past the end of input, then return value as a length.
|
||||
if (position == input.end())
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels(value)));
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels::nearest_value_for(value)));
|
||||
|
||||
// 2. If the code point at position within input is U+0025 (%), then return value as a percentage.
|
||||
if (*position == '%')
|
||||
return CSS::PercentageStyleValue::create(CSS::Percentage(value));
|
||||
|
||||
// 3. Return value as a length.
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels(value)));
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels::nearest_value_for(value)));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#rules-for-parsing-dimension-values
|
||||
|
@ -4065,7 +4065,7 @@ RefPtr<CSS::StyleValue> parse_dimension_value(StringView string)
|
|||
|
||||
// 4. If position is past the end of input, then return value as a length.
|
||||
if (position == input.end())
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels(value)));
|
||||
return CSS::LengthStyleValue::create(CSS::Length::make_px(CSSPixels::nearest_value_for(value)));
|
||||
|
||||
// 5. If the code point at position within input is not an ASCII digit, then break.
|
||||
if (!is_ascii_digit(*position))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue