LibWeb: Replace GridTrackPlacementShorthandStyleValue with ShorthandSV

This commit is contained in:
Sam Atkins 2023-09-20 16:19:37 +01:00 committed by Sam Atkins
parent 8efac89a16
commit e905072e47
Notes: sideshowbarker 2024-07-17 09:49:48 +09:00
12 changed files with 81 additions and 153 deletions

View file

@ -16,7 +16,6 @@ source_set("StyleValues") {
"FilterValueListStyleValue.cpp",
"GridAutoFlowStyleValue.cpp",
"GridTemplateAreaStyleValue.cpp",
"GridTrackPlacementShorthandStyleValue.cpp",
"GridTrackPlacementStyleValue.cpp",
"GridTrackSizeListStyleValue.cpp",
"IdentifierStyleValue.cpp",

View file

@ -94,7 +94,6 @@ set(SOURCES
CSS/StyleValues/GridAutoFlowStyleValue.cpp
CSS/StyleValues/GridTemplateAreaStyleValue.cpp
CSS/StyleValues/GridTrackPlacementStyleValue.cpp
CSS/StyleValues/GridTrackPlacementShorthandStyleValue.cpp
CSS/StyleValues/GridTrackSizeListStyleValue.cpp
CSS/StyleValues/IdentifierStyleValue.cpp
CSS/StyleValues/ImageStyleValue.cpp

View file

@ -48,7 +48,6 @@
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
@ -5525,8 +5524,11 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement(Vector<ComponentValue> con
return GridTrackPlacementStyleValue::create(GridTrackPlacement::make_span(span_or_position_value));
}
RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<ComponentValue> const& component_values)
RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(PropertyID property_id, Vector<ComponentValue> const& component_values)
{
auto start_property = (property_id == PropertyID::GridColumn) ? PropertyID::GridColumnStart : PropertyID::GridRowStart;
auto end_property = (property_id == PropertyID::GridColumn) ? PropertyID::GridColumnEnd : PropertyID::GridRowEnd;
auto tokens = TokenStream { component_values };
auto current_token = tokens.next_token().token();
@ -5552,12 +5554,18 @@ RefPtr<StyleValue> Parser::parse_grid_track_placement_shorthand_value(Vector<Com
}
auto parsed_start_value = parse_grid_track_placement(track_start_placement_tokens);
if (parsed_start_value && track_end_placement_tokens.is_empty())
return GridTrackPlacementShorthandStyleValue::create(parsed_start_value.release_nonnull()->as_grid_track_placement().grid_track_placement());
if (parsed_start_value && track_end_placement_tokens.is_empty()) {
return ShorthandStyleValue::create(property_id,
{ start_property, end_property },
{ parsed_start_value.release_nonnull(), GridTrackPlacementStyleValue::create(GridTrackPlacement::make_auto()) });
}
auto parsed_end_value = parse_grid_track_placement(track_end_placement_tokens);
if (parsed_start_value && parsed_end_value)
return GridTrackPlacementShorthandStyleValue::create(parsed_start_value.release_nonnull()->as_grid_track_placement(), parsed_end_value.release_nonnull()->as_grid_track_placement());
if (parsed_start_value && parsed_end_value) {
return ShorthandStyleValue::create(property_id,
{ start_property, end_property },
{ parsed_start_value.release_nonnull(), parsed_end_value.release_nonnull() });
}
return nullptr;
}
@ -5868,7 +5876,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
return ParseError::SyntaxError;
}
case PropertyID::GridColumn:
if (auto parsed_value = parse_grid_track_placement_shorthand_value(component_values))
if (auto parsed_value = parse_grid_track_placement_shorthand_value(property_id, component_values))
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::GridArea:
@ -5892,7 +5900,7 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::GridRow:
if (auto parsed_value = parse_grid_track_placement_shorthand_value(component_values))
if (auto parsed_value = parse_grid_track_placement_shorthand_value(property_id, component_values))
return parsed_value.release_nonnull();
return ParseError::SyntaxError;
case PropertyID::GridRowEnd:

View file

@ -260,7 +260,7 @@ private:
[[nodiscard]] RefPtr<GridAutoFlowStyleValue> parse_grid_auto_flow_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_grid_track_size_list_shorthand_value(PropertyID, Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_grid_track_placement(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_grid_track_placement_shorthand_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_grid_track_placement_shorthand_value(PropertyID, Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_grid_template_areas_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_grid_area_shorthand_value(Vector<ComponentValue> const&);
RefPtr<StyleValue> parse_grid_shorthand_value(Vector<ComponentValue> const&);

View file

@ -18,7 +18,6 @@
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
@ -327,7 +326,9 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
VERIFY(maybe_grid_column_start.value().value->is_grid_track_placement());
grid_column_start = maybe_grid_column_start.value().value->as_grid_track_placement();
}
return GridTrackPlacementShorthandStyleValue::create(grid_column_end.release_nonnull(), grid_column_start.release_nonnull());
return ShorthandStyleValue::create(property_id,
{ PropertyID::GridColumnStart, PropertyID::GridColumnEnd },
{ grid_column_end.release_nonnull(), grid_column_start.release_nonnull() });
}
case PropertyID::GridRow: {
auto maybe_grid_row_end = property(PropertyID::GridRowEnd);
@ -341,7 +342,9 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
VERIFY(maybe_grid_row_start.value().value->is_grid_track_placement());
grid_row_start = maybe_grid_row_start.value().value->as_grid_track_placement();
}
return GridTrackPlacementShorthandStyleValue::create(grid_row_end.release_nonnull(), grid_row_start.release_nonnull());
return ShorthandStyleValue::create(property_id,
{ PropertyID::GridRowStart, PropertyID::GridRowEnd },
{ grid_row_end.release_nonnull(), grid_row_start.release_nonnull() });
}
case PropertyID::GridTemplate: {
auto maybe_grid_template_areas = property(PropertyID::GridTemplateAreas);

View file

@ -36,7 +36,6 @@
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
@ -709,26 +708,12 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
}
if (property_id == CSS::PropertyID::GridColumn) {
if (value.is_grid_track_placement_shorthand()) {
auto const& shorthand = value.as_grid_track_placement_shorthand();
set_longhand_property(CSS::PropertyID::GridColumnStart, shorthand.start());
set_longhand_property(CSS::PropertyID::GridColumnEnd, shorthand.end());
return;
}
set_longhand_property(CSS::PropertyID::GridColumnStart, value);
set_longhand_property(CSS::PropertyID::GridColumnEnd, value);
return;
}
if (property_id == CSS::PropertyID::GridRow) {
if (value.is_grid_track_placement_shorthand()) {
auto const& shorthand = value.as_grid_track_placement_shorthand();
set_longhand_property(CSS::PropertyID::GridRowStart, shorthand.start());
set_longhand_property(CSS::PropertyID::GridRowEnd, shorthand.end());
return;
}
set_longhand_property(CSS::PropertyID::GridRowStart, value);
set_longhand_property(CSS::PropertyID::GridRowEnd, value);
return;

View file

@ -27,7 +27,6 @@
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>

View file

@ -82,51 +82,50 @@ private:
using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
#define ENUMERATE_STYLE_VALUE_TYPES \
__ENUMERATE_STYLE_VALUE_TYPE(Angle, angle) \
__ENUMERATE_STYLE_VALUE_TYPE(BackgroundRepeat, background_repeat) \
__ENUMERATE_STYLE_VALUE_TYPE(BackgroundSize, background_size) \
__ENUMERATE_STYLE_VALUE_TYPE(BorderRadius, border_radius) \
__ENUMERATE_STYLE_VALUE_TYPE(Calculated, calculated) \
__ENUMERATE_STYLE_VALUE_TYPE(Color, color) \
__ENUMERATE_STYLE_VALUE_TYPE(ConicGradient, conic_gradient) \
__ENUMERATE_STYLE_VALUE_TYPE(Content, content) \
__ENUMERATE_STYLE_VALUE_TYPE(CustomIdent, custom_ident) \
__ENUMERATE_STYLE_VALUE_TYPE(Display, display) \
__ENUMERATE_STYLE_VALUE_TYPE(Easing, easing) \
__ENUMERATE_STYLE_VALUE_TYPE(Edge, edge) \
__ENUMERATE_STYLE_VALUE_TYPE(FilterValueList, filter_value_list) \
__ENUMERATE_STYLE_VALUE_TYPE(Frequency, frequency) \
__ENUMERATE_STYLE_VALUE_TYPE(GridAutoFlow, grid_auto_flow) \
__ENUMERATE_STYLE_VALUE_TYPE(GridTemplateArea, grid_template_area) \
__ENUMERATE_STYLE_VALUE_TYPE(GridTrackPlacement, grid_track_placement) \
__ENUMERATE_STYLE_VALUE_TYPE(GridTrackPlacementShorthand, grid_track_placement_shorthand) \
__ENUMERATE_STYLE_VALUE_TYPE(GridTrackSizeList, grid_track_size_list) \
__ENUMERATE_STYLE_VALUE_TYPE(Identifier, identifier) \
__ENUMERATE_STYLE_VALUE_TYPE(Image, image) \
__ENUMERATE_STYLE_VALUE_TYPE(Inherit, inherit) \
__ENUMERATE_STYLE_VALUE_TYPE(Initial, initial) \
__ENUMERATE_STYLE_VALUE_TYPE(Integer, integer) \
__ENUMERATE_STYLE_VALUE_TYPE(Length, length) \
__ENUMERATE_STYLE_VALUE_TYPE(LinearGradient, linear_gradient) \
__ENUMERATE_STYLE_VALUE_TYPE(MathDepth, math_depth) \
__ENUMERATE_STYLE_VALUE_TYPE(Number, number) \
__ENUMERATE_STYLE_VALUE_TYPE(Overflow, overflow) \
__ENUMERATE_STYLE_VALUE_TYPE(Percentage, percentage) \
__ENUMERATE_STYLE_VALUE_TYPE(Position, position) \
__ENUMERATE_STYLE_VALUE_TYPE(RadialGradient, radial_gradient) \
__ENUMERATE_STYLE_VALUE_TYPE(Ratio, ratio) \
__ENUMERATE_STYLE_VALUE_TYPE(Rect, rect) \
__ENUMERATE_STYLE_VALUE_TYPE(Resolution, resolution) \
__ENUMERATE_STYLE_VALUE_TYPE(Revert, revert) \
__ENUMERATE_STYLE_VALUE_TYPE(Shadow, shadow) \
__ENUMERATE_STYLE_VALUE_TYPE(Shorthand, shorthand) \
__ENUMERATE_STYLE_VALUE_TYPE(String, string) \
__ENUMERATE_STYLE_VALUE_TYPE(Time, time) \
__ENUMERATE_STYLE_VALUE_TYPE(Transformation, transformation) \
__ENUMERATE_STYLE_VALUE_TYPE(Unresolved, unresolved) \
__ENUMERATE_STYLE_VALUE_TYPE(Unset, unset) \
__ENUMERATE_STYLE_VALUE_TYPE(URL, url) \
#define ENUMERATE_STYLE_VALUE_TYPES \
__ENUMERATE_STYLE_VALUE_TYPE(Angle, angle) \
__ENUMERATE_STYLE_VALUE_TYPE(BackgroundRepeat, background_repeat) \
__ENUMERATE_STYLE_VALUE_TYPE(BackgroundSize, background_size) \
__ENUMERATE_STYLE_VALUE_TYPE(BorderRadius, border_radius) \
__ENUMERATE_STYLE_VALUE_TYPE(Calculated, calculated) \
__ENUMERATE_STYLE_VALUE_TYPE(Color, color) \
__ENUMERATE_STYLE_VALUE_TYPE(ConicGradient, conic_gradient) \
__ENUMERATE_STYLE_VALUE_TYPE(Content, content) \
__ENUMERATE_STYLE_VALUE_TYPE(CustomIdent, custom_ident) \
__ENUMERATE_STYLE_VALUE_TYPE(Display, display) \
__ENUMERATE_STYLE_VALUE_TYPE(Easing, easing) \
__ENUMERATE_STYLE_VALUE_TYPE(Edge, edge) \
__ENUMERATE_STYLE_VALUE_TYPE(FilterValueList, filter_value_list) \
__ENUMERATE_STYLE_VALUE_TYPE(Frequency, frequency) \
__ENUMERATE_STYLE_VALUE_TYPE(GridAutoFlow, grid_auto_flow) \
__ENUMERATE_STYLE_VALUE_TYPE(GridTemplateArea, grid_template_area) \
__ENUMERATE_STYLE_VALUE_TYPE(GridTrackPlacement, grid_track_placement) \
__ENUMERATE_STYLE_VALUE_TYPE(GridTrackSizeList, grid_track_size_list) \
__ENUMERATE_STYLE_VALUE_TYPE(Identifier, identifier) \
__ENUMERATE_STYLE_VALUE_TYPE(Image, image) \
__ENUMERATE_STYLE_VALUE_TYPE(Inherit, inherit) \
__ENUMERATE_STYLE_VALUE_TYPE(Initial, initial) \
__ENUMERATE_STYLE_VALUE_TYPE(Integer, integer) \
__ENUMERATE_STYLE_VALUE_TYPE(Length, length) \
__ENUMERATE_STYLE_VALUE_TYPE(LinearGradient, linear_gradient) \
__ENUMERATE_STYLE_VALUE_TYPE(MathDepth, math_depth) \
__ENUMERATE_STYLE_VALUE_TYPE(Number, number) \
__ENUMERATE_STYLE_VALUE_TYPE(Overflow, overflow) \
__ENUMERATE_STYLE_VALUE_TYPE(Percentage, percentage) \
__ENUMERATE_STYLE_VALUE_TYPE(Position, position) \
__ENUMERATE_STYLE_VALUE_TYPE(RadialGradient, radial_gradient) \
__ENUMERATE_STYLE_VALUE_TYPE(Ratio, ratio) \
__ENUMERATE_STYLE_VALUE_TYPE(Rect, rect) \
__ENUMERATE_STYLE_VALUE_TYPE(Resolution, resolution) \
__ENUMERATE_STYLE_VALUE_TYPE(Revert, revert) \
__ENUMERATE_STYLE_VALUE_TYPE(Shadow, shadow) \
__ENUMERATE_STYLE_VALUE_TYPE(Shorthand, shorthand) \
__ENUMERATE_STYLE_VALUE_TYPE(String, string) \
__ENUMERATE_STYLE_VALUE_TYPE(Time, time) \
__ENUMERATE_STYLE_VALUE_TYPE(Transformation, transformation) \
__ENUMERATE_STYLE_VALUE_TYPE(Unresolved, unresolved) \
__ENUMERATE_STYLE_VALUE_TYPE(Unset, unset) \
__ENUMERATE_STYLE_VALUE_TYPE(URL, url) \
__ENUMERATE_STYLE_VALUE_TYPE(ValueList, value_list)
// NOTE:

View file

@ -1,34 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "GridTrackPlacementShorthandStyleValue.h"
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
namespace Web::CSS {
ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> GridTrackPlacementShorthandStyleValue::create(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> end)
{
return adopt_ref(*new (nothrow) GridTrackPlacementShorthandStyleValue(move(start), move(end)));
}
ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> GridTrackPlacementShorthandStyleValue::create(GridTrackPlacement start)
{
return adopt_ref(*new (nothrow) GridTrackPlacementShorthandStyleValue(
GridTrackPlacementStyleValue::create(start),
GridTrackPlacementStyleValue::create(GridTrackPlacement::make_auto())));
}
String GridTrackPlacementShorthandStyleValue::to_string() const
{
if (m_properties.end->grid_track_placement().is_auto())
return MUST(String::formatted("{}", m_properties.start->grid_track_placement().to_string()));
return MUST(String::formatted("{} / {}", m_properties.start->grid_track_placement().to_string(), m_properties.end->grid_track_placement().to_string()));
}
}

View file

@ -1,43 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/StyleValue.h>
namespace Web::CSS {
class GridTrackPlacementShorthandStyleValue final : public StyleValueWithDefaultOperators<GridTrackPlacementShorthandStyleValue> {
public:
static ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> create(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> end);
static ValueComparingNonnullRefPtr<GridTrackPlacementShorthandStyleValue> create(GridTrackPlacement start);
virtual ~GridTrackPlacementShorthandStyleValue() override = default;
auto start() const { return m_properties.start; }
auto end() const { return m_properties.end; }
virtual String to_string() const override;
bool properties_equal(GridTrackPlacementShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
private:
GridTrackPlacementShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> end)
: StyleValueWithDefaultOperators(Type::GridTrackPlacementShorthand)
, m_properties { .start = move(start), .end = move(end) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> start;
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> end;
bool operator==(Properties const&) const = default;
} m_properties;
};
}

View file

@ -145,6 +145,20 @@ String ShorthandStyleValue::to_string() const
return MUST(String::formatted("{}", construct_rows_string()));
return MUST(String::formatted("{} / {}", construct_rows_string(), columns.grid_track_size_list().to_string()));
}
case PropertyID::GridColumn: {
auto start = longhand(PropertyID::GridColumnStart);
auto end = longhand(PropertyID::GridColumnEnd);
if (end->as_grid_track_placement().grid_track_placement().is_auto())
return start->to_string();
return MUST(String::formatted("{} / {}", start->to_string(), end->to_string()));
}
case PropertyID::GridRow: {
auto start = longhand(PropertyID::GridRowStart);
auto end = longhand(PropertyID::GridRowEnd);
if (end->as_grid_track_placement().grid_track_placement().is_auto())
return start->to_string();
return MUST(String::formatted("{} / {}", start->to_string(), end->to_string()));
}
case PropertyID::ListStyle:
return MUST(String::formatted("{} {} {}", longhand(PropertyID::ListStylePosition)->to_string(), longhand(PropertyID::ListStyleImage)->to_string(), longhand(PropertyID::ListStyleType)->to_string()));
case PropertyID::PlaceContent: {

View file

@ -112,7 +112,6 @@ class GridRepeat;
class GridSize;
class GridTemplateAreaStyleValue;
class GridTrackPlacement;
class GridTrackPlacementShorthandStyleValue;
class GridTrackPlacementStyleValue;
class GridTrackSizeList;
class GridTrackSizeListStyleValue;