mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibWeb: Remove FooOrCalculated classes
These are unused since we now store values as `StyleValue`s before used-value time, and as their resolved type (e.g. CSSPixels) after
This commit is contained in:
Notes:
github-actions[bot]
2026-03-30 13:06:19 +00:00
Author: https://github.com/Calme1709 Commit: https://github.com/LadybirdBrowser/ladybird/commit/0219eb2ef9e Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8676 Reviewed-by: https://github.com/AtkinsSJ ✅
@@ -33,8 +33,7 @@ After parsing and style computation, longhand properties are stored as `StyleVal
|
||||
`ComputedProperties`. Any shorthands have been expanded out, and so we do not need to store them directly.
|
||||
|
||||
These longhands then need to be converted to a more usable form. To do this, add a getter to `ComputedProperties` with
|
||||
the same name as the property. It should return a type that holds the value in a compact form. Be aware that anything
|
||||
involving numbers or dimensions may be a calculation, so store it in one of the `FooOrCalculated` types.
|
||||
the same name as the property. It should return a type that holds the value in a compact form.
|
||||
|
||||
Then, `CSS/ComputedValues.h` contains three classes that are relevant:
|
||||
- `ComputedValues` holds the computed value of each property, in a flat format. Depending on whether the property is
|
||||
|
||||
@@ -100,7 +100,6 @@ set(SOURCES
|
||||
CSS/Angle.cpp
|
||||
CSS/AnimationEvent.cpp
|
||||
CSS/BooleanExpression.cpp
|
||||
CSS/CalculatedOr.cpp
|
||||
CSS/CascadedProperties.cpp
|
||||
CSS/Clip.cpp
|
||||
CSS/ComputedProperties.cpp
|
||||
|
||||
@@ -1,137 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "CalculatedOr.h"
|
||||
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
Optional<Angle> AngleOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_angle(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> AngleOrCalculated::create_style_value() const
|
||||
{
|
||||
return AngleStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<Flex> FlexOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_flex(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> FlexOrCalculated::create_style_value() const
|
||||
{
|
||||
return FlexStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<Frequency> FrequencyOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_frequency(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> FrequencyOrCalculated::create_style_value() const
|
||||
{
|
||||
return FrequencyStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<i32> IntegerOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_integer(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> IntegerOrCalculated::create_style_value() const
|
||||
{
|
||||
return IntegerStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<Length> LengthOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_length(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> LengthOrCalculated::create_style_value() const
|
||||
{
|
||||
return LengthStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<LengthOrAuto> LengthOrAutoOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_length(context).map([](auto&& length) { return LengthOrAuto { length }; });
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> LengthOrAutoOrCalculated::create_style_value() const
|
||||
{
|
||||
auto const& length_or_auto = value();
|
||||
if (length_or_auto.is_auto())
|
||||
return KeywordStyleValue::create(Keyword::Auto);
|
||||
return LengthStyleValue::create(length_or_auto.length());
|
||||
}
|
||||
|
||||
bool LengthOrAutoOrCalculated::is_auto() const
|
||||
{
|
||||
return !is_calculated() && value().is_auto();
|
||||
}
|
||||
|
||||
LengthOrCalculated LengthOrAutoOrCalculated::without_auto() const
|
||||
{
|
||||
VERIFY(!is_auto());
|
||||
if (is_calculated())
|
||||
return calculated();
|
||||
return value().length();
|
||||
}
|
||||
|
||||
Optional<double> NumberOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_number(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> NumberOrCalculated::create_style_value() const
|
||||
{
|
||||
return NumberStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<Percentage> PercentageOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_percentage(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> PercentageOrCalculated::create_style_value() const
|
||||
{
|
||||
return PercentageStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<Resolution> ResolutionOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_resolution(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> ResolutionOrCalculated::create_style_value() const
|
||||
{
|
||||
return ResolutionStyleValue::create(value());
|
||||
}
|
||||
|
||||
Optional<Time> TimeOrCalculated::resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return calculated->resolve_time(context);
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> TimeOrCalculated::create_style_value() const
|
||||
{
|
||||
return TimeStyleValue::create(value());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2023-2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/Variant.h>
|
||||
#include <LibWeb/CSS/Angle.h>
|
||||
#include <LibWeb/CSS/Flex.h>
|
||||
#include <LibWeb/CSS/Frequency.h>
|
||||
#include <LibWeb/CSS/Length.h>
|
||||
#include <LibWeb/CSS/Number.h>
|
||||
#include <LibWeb/CSS/Percentage.h>
|
||||
#include <LibWeb/CSS/Resolution.h>
|
||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||
#include <LibWeb/CSS/Time.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
template<typename Self, typename T>
|
||||
class CalculatedOr {
|
||||
public:
|
||||
CalculatedOr(T t)
|
||||
: m_value(move(t))
|
||||
{
|
||||
}
|
||||
|
||||
CalculatedOr(NonnullRefPtr<CalculatedStyleValue const> calculated)
|
||||
: m_value(move(calculated))
|
||||
{
|
||||
}
|
||||
|
||||
bool is_calculated() const { return m_value.template has<NonnullRefPtr<CalculatedStyleValue const>>(); }
|
||||
|
||||
T const& value() const
|
||||
{
|
||||
VERIFY(!is_calculated());
|
||||
return m_value.template get<T>();
|
||||
}
|
||||
|
||||
NonnullRefPtr<StyleValue const> as_style_value() const
|
||||
{
|
||||
if (is_calculated())
|
||||
return calculated();
|
||||
return create_style_value();
|
||||
}
|
||||
|
||||
NonnullRefPtr<CalculatedStyleValue const> const& calculated() const
|
||||
{
|
||||
VERIFY(is_calculated());
|
||||
return m_value.template get<NonnullRefPtr<CalculatedStyleValue const>>();
|
||||
}
|
||||
|
||||
Optional<T> resolved(CalculationResolutionContext const& context) const
|
||||
{
|
||||
return m_value.visit(
|
||||
[&](T const& t) -> Optional<T> {
|
||||
return t;
|
||||
},
|
||||
[&](NonnullRefPtr<CalculatedStyleValue const> const& calculated) {
|
||||
return resolve_calculated(calculated, context);
|
||||
});
|
||||
}
|
||||
|
||||
void serialize(StringBuilder& builder, SerializationMode mode) const
|
||||
{
|
||||
m_value.visit(
|
||||
[&builder, mode](T const& t) {
|
||||
if constexpr (IsArithmetic<T>) {
|
||||
(void)mode;
|
||||
builder.append(String::number(t));
|
||||
} else {
|
||||
t.serialize(builder, mode);
|
||||
}
|
||||
},
|
||||
[&builder, mode](NonnullRefPtr<CalculatedStyleValue const> const& calculated) {
|
||||
calculated->serialize(builder, mode);
|
||||
});
|
||||
}
|
||||
|
||||
String to_string(SerializationMode mode) const
|
||||
{
|
||||
StringBuilder builder;
|
||||
serialize(builder, mode);
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
bool is_computationally_independent() const { return as_style_value()->is_computationally_independent(); }
|
||||
|
||||
bool operator==(CalculatedOr<Self, T> const& other) const
|
||||
{
|
||||
if (is_calculated() || other.is_calculated())
|
||||
return false;
|
||||
return (m_value.template get<T>() == other.m_value.template get<T>());
|
||||
}
|
||||
|
||||
protected:
|
||||
Optional<T> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const& calculated, CalculationResolutionContext const& context) const
|
||||
{
|
||||
return static_cast<Self const*>(this)->resolve_calculated(calculated, context);
|
||||
}
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const
|
||||
{
|
||||
return static_cast<Self const*>(this)->create_style_value();
|
||||
}
|
||||
|
||||
private:
|
||||
Variant<T, NonnullRefPtr<CalculatedStyleValue const>> m_value;
|
||||
};
|
||||
|
||||
class AngleOrCalculated : public CalculatedOr<AngleOrCalculated, Angle> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<Angle> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class FlexOrCalculated : public CalculatedOr<FlexOrCalculated, Flex> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<Flex> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class FrequencyOrCalculated : public CalculatedOr<FrequencyOrCalculated, Frequency> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<Frequency> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class IntegerOrCalculated : public CalculatedOr<IntegerOrCalculated, i32> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<i32> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class LengthOrCalculated : public CalculatedOr<LengthOrCalculated, Length> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<Length> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class LengthOrAutoOrCalculated : public CalculatedOr<LengthOrAutoOrCalculated, LengthOrAuto> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<LengthOrAuto> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
bool is_auto() const;
|
||||
LengthOrCalculated without_auto() const;
|
||||
};
|
||||
|
||||
class NumberOrCalculated : public CalculatedOr<NumberOrCalculated, double> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<double> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class PercentageOrCalculated : public CalculatedOr<PercentageOrCalculated, Percentage> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<Percentage> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class ResolutionOrCalculated : public CalculatedOr<ResolutionOrCalculated, Resolution> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<Resolution> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
class TimeOrCalculated : public CalculatedOr<TimeOrCalculated, Time> {
|
||||
public:
|
||||
using CalculatedOr::CalculatedOr;
|
||||
|
||||
Optional<Time> resolve_calculated(NonnullRefPtr<CalculatedStyleValue const> const&, CalculationResolutionContext const&) const;
|
||||
NonnullRefPtr<StyleValue const> create_style_value() const;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Web::CSS::AngleOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::AngleOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string(Web::CSS::SerializationMode::Normal));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Web::CSS::FrequencyOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::FrequencyOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string(Web::CSS::SerializationMode::Normal));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Web::CSS::LengthOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::LengthOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string(Web::CSS::SerializationMode::Normal));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Web::CSS::PercentageOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::PercentageOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string(Web::CSS::SerializationMode::Normal));
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Web::CSS::TimeOrCalculated> : Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::TimeOrCalculated const& calculated_or)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, calculated_or.to_string(Web::CSS::SerializationMode::Normal));
|
||||
}
|
||||
};
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <AK/Optional.h>
|
||||
#include <LibGfx/FontCascadeList.h>
|
||||
#include <LibGfx/ScalingMode.h>
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/Clip.h>
|
||||
#include <LibWeb/CSS/ColumnCount.h>
|
||||
#include <LibWeb/CSS/CounterStyle.h>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "EasingFunction.h"
|
||||
#include <AK/Math.h>
|
||||
#include <LibWeb/CSS/Enums.h>
|
||||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "GridTrackPlacement.h"
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibWeb/CSS/BooleanExpression.h>
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/MediaFeatureID.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Ratio.h>
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include <LibWeb/CSS/CSSFunctionDeclarations.h>
|
||||
#include <LibWeb/CSS/CSSMediaRule.h>
|
||||
#include <LibWeb/CSS/CSSNestedDeclarations.h>
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/MediaList.h>
|
||||
#include <LibWeb/CSS/MediaQuery.h>
|
||||
#include <LibWeb/CSS/Parser/ErrorReporter.h>
|
||||
|
||||
@@ -332,18 +332,10 @@ private:
|
||||
Optional<Descriptor> convert_to_descriptor(AtRuleID, Declaration const&);
|
||||
|
||||
Optional<Dimension> parse_dimension(ComponentValue const&);
|
||||
Optional<AngleOrCalculated> parse_angle(TokenStream<ComponentValue>&);
|
||||
Optional<AnglePercentage> parse_angle_percentage(TokenStream<ComponentValue>&);
|
||||
Optional<FlexOrCalculated> parse_flex(TokenStream<ComponentValue>&);
|
||||
Optional<FrequencyOrCalculated> parse_frequency(TokenStream<ComponentValue>&);
|
||||
Optional<FrequencyPercentage> parse_frequency_percentage(TokenStream<ComponentValue>&);
|
||||
Optional<IntegerOrCalculated> parse_integer(TokenStream<ComponentValue>&);
|
||||
Optional<LengthOrCalculated> parse_length(TokenStream<ComponentValue>&);
|
||||
Optional<LengthPercentage> parse_length_percentage(TokenStream<ComponentValue>&);
|
||||
Optional<NumberOrCalculated> parse_number(TokenStream<ComponentValue>&);
|
||||
Optional<NumberPercentage> parse_number_percentage(TokenStream<ComponentValue>&);
|
||||
Optional<ResolutionOrCalculated> parse_resolution(TokenStream<ComponentValue>&);
|
||||
Optional<TimeOrCalculated> parse_time(TokenStream<ComponentValue>&);
|
||||
Optional<TimePercentage> parse_time_percentage(TokenStream<ComponentValue>&);
|
||||
|
||||
RefPtr<StyleValue const> parse_source_size_value(TokenStream<ComponentValue>&);
|
||||
|
||||
@@ -252,17 +252,6 @@ Optional<Dimension> Parser::parse_dimension(ComponentValue const& component_valu
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<AngleOrCalculated> Parser::parse_angle(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_angle_value(tokens)) {
|
||||
if (value->is_angle())
|
||||
return value->as_angle().angle();
|
||||
if (value->is_calculated())
|
||||
return AngleOrCalculated { value->as_calculated() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<AnglePercentage> Parser::parse_angle_percentage(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_angle_percentage_value(tokens)) {
|
||||
@@ -276,28 +265,6 @@ Optional<AnglePercentage> Parser::parse_angle_percentage(TokenStream<ComponentVa
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<FlexOrCalculated> Parser::parse_flex(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_flex_value(tokens)) {
|
||||
if (value->is_flex())
|
||||
return value->as_flex().flex();
|
||||
if (value->is_calculated())
|
||||
return FlexOrCalculated { value->as_calculated() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<FrequencyOrCalculated> Parser::parse_frequency(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_frequency_value(tokens)) {
|
||||
if (value->is_frequency())
|
||||
return value->as_frequency().frequency();
|
||||
if (value->is_calculated())
|
||||
return FrequencyOrCalculated { value->as_calculated() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<FrequencyPercentage> Parser::parse_frequency_percentage(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_frequency_percentage_value(tokens)) {
|
||||
@@ -311,32 +278,6 @@ Optional<FrequencyPercentage> Parser::parse_frequency_percentage(TokenStream<Com
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<IntegerOrCalculated> Parser::parse_integer(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
// FIXME: We don't have a way to represent tree counting functions within IntegerOrCalculated, we should avoid
|
||||
// parsing directly to IntegerOrCalculated unless tree counting functions are disallowed in the relevant
|
||||
// context
|
||||
if (auto value = parse_integer_value(tokens)) {
|
||||
if (value->is_integer())
|
||||
return value->as_integer().integer();
|
||||
if (value->is_calculated())
|
||||
return IntegerOrCalculated { value->as_calculated() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<LengthOrCalculated> Parser::parse_length(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_length_value(tokens)) {
|
||||
if (value->is_length())
|
||||
return value->as_length().length();
|
||||
if (value->is_calculated())
|
||||
return LengthOrCalculated { value->as_calculated() };
|
||||
// FIXME: Deal with ->is_anchor_size()
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<LengthPercentage> Parser::parse_length_percentage(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_length_percentage_value(tokens)) {
|
||||
@@ -351,20 +292,6 @@ Optional<LengthPercentage> Parser::parse_length_percentage(TokenStream<Component
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<NumberOrCalculated> Parser::parse_number(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
// FIXME: We don't have a way to represent tree counting functions within NumberOrCalculated, we should avoid
|
||||
// parsing directly to NumberOrCalculated unless tree counting functions are disallowed in the relevant
|
||||
// context
|
||||
if (auto value = parse_number_value(tokens)) {
|
||||
if (value->is_number())
|
||||
return value->as_number().number();
|
||||
if (value->is_calculated())
|
||||
return NumberOrCalculated { value->as_calculated() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<NumberPercentage> Parser::parse_number_percentage(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_number_percentage_value(tokens)) {
|
||||
@@ -378,28 +305,6 @@ Optional<NumberPercentage> Parser::parse_number_percentage(TokenStream<Component
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<ResolutionOrCalculated> Parser::parse_resolution(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_resolution_value(tokens)) {
|
||||
if (value->is_resolution())
|
||||
return value->as_resolution().resolution();
|
||||
if (value->is_calculated())
|
||||
return ResolutionOrCalculated { value->as_calculated() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<TimeOrCalculated> Parser::parse_time(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_time_value(tokens)) {
|
||||
if (value->is_time())
|
||||
return value->as_time().time();
|
||||
if (value->is_calculated())
|
||||
return TimeOrCalculated { value->as_calculated() };
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Optional<TimePercentage> Parser::parse_time_percentage(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
if (auto value = parse_time_percentage_value(tokens)) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/Percentage.h>
|
||||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <AK/Optional.h>
|
||||
#include <LibGfx/Color.h>
|
||||
#include <LibGfx/Cursor.h>
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/Length.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
#include <LibWeb/Export.h>
|
||||
|
||||
|
||||
@@ -218,7 +218,6 @@ class AddFunctionStyleValue;
|
||||
class AnchorStyleValue;
|
||||
class AnchorSizeStyleValue;
|
||||
class Angle;
|
||||
class AngleOrCalculated;
|
||||
class AnglePercentage;
|
||||
class AngleStyleValue;
|
||||
class BackgroundSizeStyleValue;
|
||||
@@ -312,7 +311,6 @@ class ExplicitGridTrack;
|
||||
class FilterValueListStyleValue;
|
||||
class FitContentStyleValue;
|
||||
class Flex;
|
||||
class FlexOrCalculated;
|
||||
class FlexStyleValue;
|
||||
class FontComputer;
|
||||
class FontFace;
|
||||
@@ -321,7 +319,6 @@ class FontSourceStyleValue;
|
||||
class FontStyleStyleValue;
|
||||
class FontVariantAlternatesFunctionStyleValue;
|
||||
class Frequency;
|
||||
class FrequencyOrCalculated;
|
||||
class FrequencyPercentage;
|
||||
class FrequencyStyleValue;
|
||||
class GridAutoFlowStyleValue;
|
||||
@@ -338,15 +335,12 @@ class GuaranteedInvalidStyleValue;
|
||||
class HSLColorStyleValue;
|
||||
class HWBColorStyleValue;
|
||||
class ImageStyleValue;
|
||||
class IntegerOrCalculated;
|
||||
class IntegerStyleValue;
|
||||
class InvalidationSet;
|
||||
class KeywordStyleValue;
|
||||
class Length;
|
||||
class LengthBox;
|
||||
class LengthOrAuto;
|
||||
class LengthOrAutoOrCalculated;
|
||||
class LengthOrCalculated;
|
||||
class LengthPercentage;
|
||||
class LengthPercentageOrAuto;
|
||||
class LengthStyleValue;
|
||||
@@ -357,7 +351,6 @@ class MediaQuery;
|
||||
class MediaQueryList;
|
||||
class MediaQueryListEvent;
|
||||
class Number;
|
||||
class NumberOrCalculated;
|
||||
class NumberStyleValue;
|
||||
class NumericType;
|
||||
class OKLabColorStyleValue;
|
||||
@@ -366,7 +359,6 @@ class OpenTypeTaggedStyleValue;
|
||||
class ParsedFontFace;
|
||||
class PendingSubstitutionStyleValue;
|
||||
class Percentage;
|
||||
class PercentageOrCalculated;
|
||||
class PercentageStyleValue;
|
||||
class PositionStyleValue;
|
||||
class PropertyNameAndID;
|
||||
@@ -378,7 +370,6 @@ class RatioStyleValue;
|
||||
class RectStyleValue;
|
||||
class RepeatStyleStyleValue;
|
||||
class Resolution;
|
||||
class ResolutionOrCalculated;
|
||||
class ResolutionStyleValue;
|
||||
class RGBColorStyleValue;
|
||||
class Screen;
|
||||
@@ -405,7 +396,6 @@ class SVGPaint;
|
||||
class TextIndentStyleValue;
|
||||
class TextUnderlinePositionStyleValue;
|
||||
class Time;
|
||||
class TimeOrCalculated;
|
||||
class TimePercentage;
|
||||
class TimeStyleValue;
|
||||
template<typename T>
|
||||
@@ -482,6 +472,7 @@ enum class WritingMode : u8;
|
||||
struct BackgroundLayerData;
|
||||
struct CalculationContext;
|
||||
struct CalculationResolutionContext;
|
||||
struct ComputationContext;
|
||||
struct CSSStyleSheetInit;
|
||||
struct FunctionParameterInternal;
|
||||
struct GridRepeatParams;
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
|
||||
#include <AK/Variant.h>
|
||||
#include <LibURL/URL.h>
|
||||
#include <LibWeb/CSS/CalculatedOr.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
#include <LibWeb/PixelUnits.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user