Files
ladybird/Libraries/LibWeb/CSS/NumericRange.h
Callum Law 76250ba142 LibWeb: Validate literal numeric values at parse time
This brings a couple of advantages:
 - Previously we relied on the caller validating the parsed value was in
   bounds after the fact - this was usually fine but there are a couple
   of places that it was forgotten (see the tests added in this commit),
   requiring the bounds to be passed as arguments makes us consider the
   desired range more explicitly.
 - In a future commit we will use the passed bounds as the clamping
   bounds for computed values, removing the need for the existing
   `ValueParsingContext` based method we have at the moment.
 - Generating code is easier with this approach
2026-04-22 14:24:12 +01:00

29 lines
790 B
C++

/*
* Copyright (c) 2025, Callum Law <callumlaw1709@outlook.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/Forward.h>
namespace Web::CSS {
struct NumericRange {
double min;
double max;
bool contains(double value) const { return value >= min && value <= max; }
};
using NumericRangesByValueType = HashMap<ValueType, NumericRange>;
constexpr NumericRange infinite_range = { AK::NumericLimits<float>::lowest(), AK::NumericLimits<float>::max() };
constexpr NumericRange non_negative_range = { 0, AK::NumericLimits<float>::max() };
constexpr NumericRange infinite_integer_range = { AK::NumericLimits<i32>::min(), AK::NumericLimits<i32>::max() };
constexpr NumericRange non_negative_integer_range = { 0, AK::NumericLimits<i32>::max() };
}