mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb: Implement basic CSS random() function
At the moment this is limited to only fixed value sharing and does not support step values
This commit is contained in:
parent
8944130fde
commit
2a5e389f63
Notes:
github-actions[bot]
2025-12-01 11:02:05 +00:00
Author: https://github.com/Calme1709
Commit: 2a5e389f63
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6707
Reviewed-by: https://github.com/AtkinsSJ ✅
Reviewed-by: https://github.com/gmta
17 changed files with 380 additions and 31 deletions
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Callum Law <callumlaw1709@outlook.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "RandomValueSharingStyleValue.h"
|
||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> RandomValueSharingStyleValue::absolutized(ComputationContext const& computation_context) const
|
||||
{
|
||||
if (m_fixed_value) {
|
||||
auto const& absolutized_fixed_value = m_fixed_value->absolutized(computation_context);
|
||||
|
||||
if (m_fixed_value == absolutized_fixed_value)
|
||||
return *this;
|
||||
|
||||
return RandomValueSharingStyleValue::create_fixed(absolutized_fixed_value);
|
||||
}
|
||||
|
||||
TODO();
|
||||
}
|
||||
|
||||
double RandomValueSharingStyleValue::random_base_value() const
|
||||
{
|
||||
VERIFY(m_fixed_value);
|
||||
VERIFY(m_fixed_value->is_number() || (m_fixed_value->is_calculated() && m_fixed_value->as_calculated().resolves_to_number()));
|
||||
|
||||
if (m_fixed_value->is_number())
|
||||
return m_fixed_value->as_number().number();
|
||||
|
||||
if (m_fixed_value->is_calculated())
|
||||
return m_fixed_value->as_calculated().resolve_number({}).value();
|
||||
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
String RandomValueSharingStyleValue::to_string(SerializationMode serialization_mode) const
|
||||
{
|
||||
if (m_fixed_value)
|
||||
return MUST(String::formatted("fixed {}", m_fixed_value->to_string(serialization_mode)));
|
||||
|
||||
TODO();
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue