mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-10 18:10:56 +09:00
LibWeb: Implement CSS sin()
This commit is contained in:
parent
ba7af82c5c
commit
c73f476915
Notes:
sideshowbarker
2024-07-17 09:47:09 +09:00
Author: https://github.com/stelar7
Commit: c73f476915
Pull-request: https://github.com/SerenityOS/serenity/pull/19165
Reviewed-by: https://github.com/AtkinsSJ ✅
6 changed files with 125 additions and 0 deletions
|
@ -24,6 +24,14 @@ static bool is_dimension(CalculatedStyleValue::ResolvedType type)
|
|||
&& type != CalculatedStyleValue::ResolvedType::Percentage;
|
||||
}
|
||||
|
||||
static double resolve_value_radians(CalculatedStyleValue::CalculationResult::Value value)
|
||||
{
|
||||
return value.visit(
|
||||
[](Number const& number) { return number.value(); },
|
||||
[](Angle const& angle) { return angle.to_radians(); },
|
||||
[](auto const&) { VERIFY_NOT_REACHED(); return 0.0; });
|
||||
};
|
||||
|
||||
static double resolve_value(CalculatedStyleValue::CalculationResult::Value value, Optional<Length::ResolutionContext const&> context)
|
||||
{
|
||||
return value.visit(
|
||||
|
@ -842,6 +850,60 @@ ErrorOr<void> ConstantCalculationNode::dump(StringBuilder& builder, int indent)
|
|||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<NonnullOwnPtr<SinCalculationNode>> SinCalculationNode::create(NonnullOwnPtr<CalculationNode> value)
|
||||
{
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) SinCalculationNode(move(value)));
|
||||
}
|
||||
|
||||
SinCalculationNode::SinCalculationNode(NonnullOwnPtr<CalculationNode> value)
|
||||
: CalculationNode(Type::Sin)
|
||||
, m_value(move(value))
|
||||
{
|
||||
}
|
||||
|
||||
SinCalculationNode::~SinCalculationNode() = default;
|
||||
|
||||
ErrorOr<String> SinCalculationNode::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
builder.append("sin("sv);
|
||||
builder.append(TRY(m_value->to_string()));
|
||||
builder.append(")"sv);
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
Optional<CalculatedStyleValue::ResolvedType> SinCalculationNode::resolved_type() const
|
||||
{
|
||||
return CalculatedStyleValue::ResolvedType::Number;
|
||||
}
|
||||
|
||||
bool SinCalculationNode::contains_percentage() const
|
||||
{
|
||||
return m_value->contains_percentage();
|
||||
}
|
||||
|
||||
CalculatedStyleValue::CalculationResult SinCalculationNode::resolve(Optional<Length::ResolutionContext const&> context, CalculatedStyleValue::PercentageBasis const& percentage_basis) const
|
||||
{
|
||||
auto node_a = m_value->resolve(context, percentage_basis);
|
||||
auto node_a_value = resolve_value_radians(node_a.value());
|
||||
auto result = sin(node_a_value);
|
||||
|
||||
return { Number(Number::Type::Number, result) };
|
||||
}
|
||||
|
||||
ErrorOr<void> SinCalculationNode::for_each_child_node(Function<ErrorOr<void>(NonnullOwnPtr<CalculationNode>&)> const& callback)
|
||||
{
|
||||
TRY(m_value->for_each_child_node(callback));
|
||||
TRY(callback(m_value));
|
||||
return {};
|
||||
}
|
||||
|
||||
ErrorOr<void> SinCalculationNode::dump(StringBuilder& builder, int indent) const
|
||||
{
|
||||
TRY(builder.try_appendff("{: >{}}SIN: {}\n", "", indent, TRY(to_string())));
|
||||
return {};
|
||||
}
|
||||
|
||||
void CalculatedStyleValue::CalculationResult::add(CalculationResult const& other, Optional<Length::ResolutionContext const&> context, PercentageBasis const& percentage_basis)
|
||||
{
|
||||
add_or_subtract_internal(SumOperation::Add, other, context, percentage_basis);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue