mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-11 18:50:50 +00:00
LibWeb/CSS: Implement "consistent type" concept on CSSNumericType
This commit is contained in:
parent
2192868a0e
commit
9cbd08a330
Notes:
github-actions[bot]
2024-12-21 17:15:39 +00:00
Author: https://github.com/AtkinsSJ
Commit: 9cbd08a330
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2966
2 changed files with 39 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2023-2024, Sam Atkins <sam@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -263,6 +263,39 @@ CSSNumericType CSSNumericType::inverted() const
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-values-4/#css-consistent-typec
|
||||||
|
bool CSSNumericType::has_consistent_type_with(CSSNumericType const& other) const
|
||||||
|
{
|
||||||
|
// Two or more calculations have a consistent type if adding the types doesn’t result in failure.
|
||||||
|
return added_to(other).has_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-values-4/#css-consistent-typec
|
||||||
|
Optional<CSSNumericType> CSSNumericType::consistent_type(CSSNumericType const& other) const
|
||||||
|
{
|
||||||
|
// The consistent type is the result of the type addition.
|
||||||
|
return added_to(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.csswg.org/css-values-4/#css-make-a-type-consistent
|
||||||
|
Optional<CSSNumericType> CSSNumericType::made_consistent_with(CSSNumericType const& input) const
|
||||||
|
{
|
||||||
|
auto base = *this;
|
||||||
|
|
||||||
|
// 1. If both base and input have different non-null percent hints, they can’t be made consistent. Return failure.
|
||||||
|
auto base_percent_hint = base.percent_hint();
|
||||||
|
auto input_percent_hint = input.percent_hint();
|
||||||
|
if (base_percent_hint.has_value() && input_percent_hint.has_value() && base_percent_hint != input_percent_hint)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
// 2. If base has a null percent hint set base’s percent hint to input’s percent hint.
|
||||||
|
if (!base_percent_hint.has_value())
|
||||||
|
base.set_percent_hint(input_percent_hint);
|
||||||
|
|
||||||
|
// 3. Return base.
|
||||||
|
return base;
|
||||||
|
}
|
||||||
|
|
||||||
// https://drafts.css-houdini.org/css-typed-om-1/#apply-the-percent-hint
|
// https://drafts.css-houdini.org/css-typed-om-1/#apply-the-percent-hint
|
||||||
void CSSNumericType::apply_percent_hint(BaseType hint)
|
void CSSNumericType::apply_percent_hint(BaseType hint)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
* Copyright (c) 2023-2024, Sam Atkins <sam@ladybird.org>
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
@ -63,6 +63,10 @@ public:
|
||||||
Optional<CSSNumericType> multiplied_by(CSSNumericType const& other) const;
|
Optional<CSSNumericType> multiplied_by(CSSNumericType const& other) const;
|
||||||
CSSNumericType inverted() const;
|
CSSNumericType inverted() const;
|
||||||
|
|
||||||
|
bool has_consistent_type_with(CSSNumericType const& other) const;
|
||||||
|
Optional<CSSNumericType> consistent_type(CSSNumericType const& other) const;
|
||||||
|
Optional<CSSNumericType> made_consistent_with(CSSNumericType const& other) const;
|
||||||
|
|
||||||
bool matches_angle() const { return matches_dimension(BaseType::Angle); }
|
bool matches_angle() const { return matches_dimension(BaseType::Angle); }
|
||||||
bool matches_angle_percentage() const { return matches_dimension_percentage(BaseType::Angle); }
|
bool matches_angle_percentage() const { return matches_dimension_percentage(BaseType::Angle); }
|
||||||
bool matches_flex() const { return matches_dimension(BaseType::Flex); }
|
bool matches_flex() const { return matches_dimension(BaseType::Flex); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue