LibWeb: Replace FitContentSV with KeywordSV and FunctionSV
The `fit-content` keyword is stored as a `KeywordStyleValue` and `fit-content()` function is stored as `FunctionStyleValue`
This commit is contained in:
parent
3bfebf862b
commit
4faab1aa57
15 changed files with 22 additions and 148 deletions
|
|
@ -257,7 +257,6 @@ set(SOURCES
|
|||
CSS/StyleValues/EasingStyleValue.cpp
|
||||
CSS/StyleValues/EdgeStyleValue.cpp
|
||||
CSS/StyleValues/FilterValueListStyleValue.cpp
|
||||
CSS/StyleValues/FitContentStyleValue.cpp
|
||||
CSS/StyleValues/FunctionStyleValue.cpp
|
||||
CSS/StyleValues/FontSourceStyleValue.cpp
|
||||
CSS/StyleValues/FontStyleStyleValue.cpp
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
#include <LibWeb/CSS/PropertyNameAndID.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/CSS/StyleValues/ColorFunctionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FunctionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
||||
|
|
@ -317,8 +317,8 @@ static NonnullRefPtr<StyleValue const> style_value_for_size(Size const& size)
|
|||
return KeywordStyleValue::create(Keyword::MaxContent);
|
||||
if (size.is_fit_content()) {
|
||||
if (auto available_space = size.fit_content_available_space(); available_space.has_value())
|
||||
return FitContentStyleValue::create(style_value_for_length_percentage(available_space.release_value()));
|
||||
return FitContentStyleValue::create();
|
||||
return FunctionStyleValue::create("fit-content"_fly_string, style_value_for_length_percentage(available_space.release_value()));
|
||||
return KeywordStyleValue::create(Keyword::FitContent);
|
||||
}
|
||||
TODO();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FunctionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "GridTrackSize.h"
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/CSS/Size.h>
|
||||
#include <LibWeb/CSS/StyleValues/FunctionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
|
@ -54,7 +55,13 @@ bool GridSize::is_flexible_length() const
|
|||
|
||||
bool GridSize::is_fit_content() const
|
||||
{
|
||||
return m_value->is_fit_content();
|
||||
if (m_value->to_keyword() == Keyword::FitContent)
|
||||
return true;
|
||||
|
||||
if (m_value->is_function() && m_value->as_function().name() == "fit-content"_fly_string)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GridSize::is_max_content() const
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
|
|
@ -1721,18 +1720,6 @@ static RefPtr<StyleValue const> interpolate_value_impl(DOM::Element& element, Ca
|
|||
|
||||
return FontStyleStyleValue::create(*keyword_to_font_style_keyword(interpolated_font_style->to_keyword()));
|
||||
}
|
||||
case StyleValue::Type::FitContent: {
|
||||
auto const& from_length_percentage = from.as_fit_content().length_percentage_style_value();
|
||||
auto const& to_length_percentage = to.as_fit_content().length_percentage_style_value();
|
||||
if (!from_length_percentage || !to_length_percentage)
|
||||
return {};
|
||||
|
||||
auto interpolated_length_percentage = interpolate_value_impl(element, calculation_context, *from_length_percentage, *to_length_percentage, delta, allow_discrete);
|
||||
if (!interpolated_length_percentage)
|
||||
return {};
|
||||
|
||||
return FitContentStyleValue::create(interpolated_length_percentage.release_nonnull());
|
||||
}
|
||||
case StyleValue::Type::Flex: {
|
||||
auto interpolated_value = interpolate_raw(from.as_flex().flex().to_fr(), to.as_flex().flex().to_fr(), delta, calculation_context.accepted_ranges_by_type.get(ValueType::Flex));
|
||||
return FlexStyleValue::create(Flex::make_fr(interpolated_value));
|
||||
|
|
@ -2499,18 +2486,6 @@ RefPtr<StyleValue const> composite_value(PropertyID property_id, StyleValue cons
|
|||
|
||||
return {};
|
||||
}
|
||||
case StyleValue::Type::FitContent: {
|
||||
auto underlying_length_percentage = underlying_value.as_fit_content().length_percentage_style_value();
|
||||
auto animated_length_percentage = animated_value.as_fit_content().length_percentage_style_value();
|
||||
if (!underlying_length_percentage || !animated_length_percentage)
|
||||
return {};
|
||||
|
||||
auto composited_length_percentage = composite_value(property_id, *underlying_length_percentage, *animated_length_percentage, composite_operation);
|
||||
if (!composited_length_percentage)
|
||||
return {};
|
||||
|
||||
return FitContentStyleValue::create(composited_length_percentage.release_nonnull());
|
||||
}
|
||||
case StyleValue::Type::Flex: {
|
||||
auto result = composite_raw_values(underlying_value.as_flex().flex().to_fr(), animated_value.as_flex().flex().to_fr());
|
||||
return FlexStyleValue::create(Flex::make_fr(result));
|
||||
|
|
|
|||
|
|
@ -270,6 +270,7 @@
|
|||
"fill-box",
|
||||
"filled-circled-decimal",
|
||||
"fine",
|
||||
"fit-content",
|
||||
"fixed",
|
||||
"flat",
|
||||
"flex",
|
||||
|
|
|
|||
|
|
@ -367,7 +367,7 @@ private:
|
|||
RefPtr<RadialSizeStyleValue const> parse_radial_size(TokenStream<ComponentValue>&);
|
||||
RefPtr<StyleValue const> parse_basic_shape_value(TokenStream<ComponentValue>&);
|
||||
|
||||
RefPtr<FitContentStyleValue const> parse_fit_content_value(TokenStream<ComponentValue>&);
|
||||
RefPtr<StyleValue const> parse_fit_content_value(TokenStream<ComponentValue>&);
|
||||
|
||||
Optional<Vector<ColorStopListElement>> parse_color_stop_list(TokenStream<ComponentValue>& tokens, auto parse_position);
|
||||
Optional<Vector<ColorStopListElement>> parse_linear_color_stop_list(TokenStream<ComponentValue>&);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
|
|
|
|||
|
|
@ -44,7 +44,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontSourceStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
|
||||
|
|
@ -3481,14 +3480,14 @@ RefPtr<RadialSizeStyleValue const> Parser::parse_radial_size(TokenStream<Compone
|
|||
return RadialSizeStyleValue::create(values);
|
||||
}
|
||||
|
||||
RefPtr<FitContentStyleValue const> Parser::parse_fit_content_value(TokenStream<ComponentValue>& tokens)
|
||||
RefPtr<StyleValue const> Parser::parse_fit_content_value(TokenStream<ComponentValue>& tokens)
|
||||
{
|
||||
auto transaction = tokens.begin_transaction();
|
||||
auto& component_value = tokens.consume_a_token();
|
||||
|
||||
if (component_value.is_ident("fit-content"sv)) {
|
||||
transaction.commit();
|
||||
return FitContentStyleValue::create();
|
||||
return KeywordStyleValue::create(Keyword::FitContent);
|
||||
}
|
||||
|
||||
if (!component_value.is_function())
|
||||
|
|
@ -3507,7 +3506,7 @@ RefPtr<FitContentStyleValue const> Parser::parse_fit_content_value(TokenStream<C
|
|||
return nullptr;
|
||||
|
||||
transaction.commit();
|
||||
return FitContentStyleValue::create(length_percentage_value.release_nonnull());
|
||||
return FunctionStyleValue::create("fit-content"_fly_string, length_percentage_value.release_nonnull());
|
||||
}
|
||||
|
||||
RefPtr<StyleValue const> Parser::parse_font_style_value(TokenStream<ComponentValue>& tokens)
|
||||
|
|
@ -4629,7 +4628,7 @@ Optional<ExplicitGridTrack> Parser::parse_grid_track_size(TokenStream<ComponentV
|
|||
if (function_tokens.has_next_token())
|
||||
return {};
|
||||
transaction.commit();
|
||||
return ExplicitGridTrack(GridSize(FitContentStyleValue::create(maybe_length_percentage.release_nonnull())));
|
||||
return ExplicitGridTrack(GridSize(FunctionStyleValue::create("fit-content"_fly_string, maybe_length_percentage.release_nonnull())));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
#include <LibWeb/CSS/Size.h>
|
||||
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FunctionStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
|
@ -89,6 +89,8 @@ Size Size::from_style_value(NonnullRefPtr<StyleValue const> const& value)
|
|||
switch (value->to_keyword()) {
|
||||
case Keyword::Auto:
|
||||
return Size::make_auto();
|
||||
case Keyword::FitContent:
|
||||
return Size::make_fit_content();
|
||||
case Keyword::MinContent:
|
||||
return Size::make_min_content();
|
||||
case Keyword::MaxContent:
|
||||
|
|
@ -99,12 +101,8 @@ Size Size::from_style_value(NonnullRefPtr<StyleValue const> const& value)
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
}
|
||||
if (value->is_fit_content()) {
|
||||
auto const& fit_content = value->as_fit_content();
|
||||
if (auto length_percentage = fit_content.length_percentage(); length_percentage.has_value())
|
||||
return Size::make_fit_content(length_percentage.release_value());
|
||||
return Size::make_fit_content();
|
||||
}
|
||||
if (value->is_function() && value->as_function().name() == "fit-content"_fly_string)
|
||||
return Size::make_fit_content(LengthPercentage::from_style_value(value->as_function().value()));
|
||||
|
||||
if (value->is_calculated())
|
||||
return Size::make_calculated(value->as_calculated());
|
||||
|
|
|
|||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
|
||||
* Copyright (c) 2026, Callum Law <callumlaw1709@outlook.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "FitContentStyleValue.h"
|
||||
#include <LibWeb/CSS/PercentageOr.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ValueComparingNonnullRefPtr<FitContentStyleValue const> FitContentStyleValue::create()
|
||||
{
|
||||
return adopt_ref(*new (nothrow) FitContentStyleValue());
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<FitContentStyleValue const> FitContentStyleValue::create(NonnullRefPtr<StyleValue const> length_percentage)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) FitContentStyleValue(move(length_percentage)));
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue const> FitContentStyleValue::absolutized(ComputationContext const& computation_context) const
|
||||
{
|
||||
if (!m_length_percentage)
|
||||
return *this;
|
||||
|
||||
auto absolutized_length_percentage = m_length_percentage->absolutized(computation_context);
|
||||
if (absolutized_length_percentage == m_length_percentage)
|
||||
return *this;
|
||||
|
||||
return FitContentStyleValue::create(absolutized_length_percentage);
|
||||
}
|
||||
|
||||
void FitContentStyleValue::serialize(StringBuilder& builder, SerializationMode mode) const
|
||||
{
|
||||
if (!m_length_percentage) {
|
||||
builder.append("fit-content"sv);
|
||||
return;
|
||||
}
|
||||
builder.append("fit-content("sv);
|
||||
m_length_percentage->serialize(builder, mode);
|
||||
builder.append(')');
|
||||
}
|
||||
|
||||
bool FitContentStyleValue::equals(StyleValue const& other) const
|
||||
{
|
||||
if (type() != other.type())
|
||||
return false;
|
||||
return m_length_percentage == other.as_fit_content().m_length_percentage;
|
||||
}
|
||||
|
||||
Optional<LengthPercentage> FitContentStyleValue::length_percentage() const
|
||||
{
|
||||
if (!m_length_percentage)
|
||||
return {};
|
||||
|
||||
return LengthPercentage::from_style_value(*m_length_percentage);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Andreas Kling <andreas@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class FitContentStyleValue final : public StyleValue {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<FitContentStyleValue const> create();
|
||||
static ValueComparingNonnullRefPtr<FitContentStyleValue const> create(NonnullRefPtr<StyleValue const> length_percentage);
|
||||
virtual ~FitContentStyleValue() override = default;
|
||||
|
||||
virtual ValueComparingNonnullRefPtr<StyleValue const> absolutized(ComputationContext const& computation_context) const override;
|
||||
virtual void serialize(StringBuilder& builder, SerializationMode mode) const override;
|
||||
|
||||
bool equals(StyleValue const& other) const override;
|
||||
|
||||
virtual bool is_computationally_independent() const override { return !m_length_percentage || m_length_percentage->is_computationally_independent(); }
|
||||
|
||||
[[nodiscard]] Optional<LengthPercentage> length_percentage() const;
|
||||
RefPtr<StyleValue const> length_percentage_style_value() const { return m_length_percentage; }
|
||||
|
||||
private:
|
||||
FitContentStyleValue(ValueComparingRefPtr<StyleValue const> length_percentage = {})
|
||||
: StyleValue(Type::FitContent)
|
||||
, m_length_percentage(move(length_percentage))
|
||||
{
|
||||
}
|
||||
|
||||
ValueComparingRefPtr<StyleValue const> m_length_percentage;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -38,7 +38,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontSourceStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ namespace Web::CSS {
|
|||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Easing, easing, EasingStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Edge, edge, EdgeStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(FilterValueList, filter_value_list, FilterValueListStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(FitContent, fit_content, FitContentStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Function, function, FunctionStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(Flex, flex, FlexStyleValue) \
|
||||
__ENUMERATE_CSS_STYLE_VALUE_TYPE(FontSource, font_source, FontSourceStyleValue) \
|
||||
|
|
|
|||
|
|
@ -319,7 +319,6 @@ class EasingStyleValue;
|
|||
class EdgeStyleValue;
|
||||
class ExplicitGridTrack;
|
||||
class FilterValueListStyleValue;
|
||||
class FitContentStyleValue;
|
||||
class Flex;
|
||||
class FlexStyleValue;
|
||||
class FontComputer;
|
||||
|
|
|
|||
Loading…
Reference in a new issue