ladybird/Libraries/LibWeb/CSS/CalculationResolutionContext.h
Callum Law 5b9a36b172 LibWeb: Pass AbstractElement in ComputationContext
Passing the `AbstractElement` rather than the
`TreeCountingFunctionResolutionContext` allows us to only compute the
resolution context when necessary (i.e. when we actually need to resolve
a tree counting function)
2025-10-22 00:01:30 +02:00

34 lines
1,017 B
C++

/*
* Copyright (c) 2025, Callum Law <callumlaw1709@outlook.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/Angle.h>
#include <LibWeb/CSS/Frequency.h>
#include <LibWeb/CSS/Length.h>
#include <LibWeb/CSS/StyleValues/ComputationContext.h>
#include <LibWeb/CSS/Time.h>
namespace Web::CSS {
struct CalculationResolutionContext {
using PercentageBasis = Variant<Empty, Angle, Frequency, Length, Time>;
PercentageBasis percentage_basis {};
Optional<Length::ResolutionContext> length_resolution_context {};
Optional<DOM::AbstractElement> abstract_element {};
static CalculationResolutionContext from_computation_context(ComputationContext const& computation_context, PercentageBasis percentage_basis = {})
{
return {
.percentage_basis = percentage_basis,
.length_resolution_context = computation_context.length_resolution_context,
.abstract_element = computation_context.abstract_element
};
}
};
}