mirror of
https://github.com/RGBCube/serenity
synced 2025-07-23 08:17:34 +00:00
LibWeb: Replace GridTrackPlacementShorthandStyleValue with ShorthandSV
This commit is contained in:
parent
8efac89a16
commit
e905072e47
12 changed files with 81 additions and 153 deletions
|
@ -16,7 +16,6 @@ source_set("StyleValues") {
|
|||
"FilterValueListStyleValue.cpp",
|
||||
"GridAutoFlowStyleValue.cpp",
|
||||
"GridTemplateAreaStyleValue.cpp",
|
||||
"GridTrackPlacementShorthandStyleValue.cpp",
|
||||
"GridTrackPlacementStyleValue.cpp",
|
||||
"GridTrackSizeListStyleValue.cpp",
|
||||
"IdentifierStyleValue.cpp",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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&);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -100,7 +100,6 @@ using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
|
|||
__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) \
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
|
@ -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: {
|
||||
|
|
|
@ -112,7 +112,6 @@ class GridRepeat;
|
|||
class GridSize;
|
||||
class GridTemplateAreaStyleValue;
|
||||
class GridTrackPlacement;
|
||||
class GridTrackPlacementShorthandStyleValue;
|
||||
class GridTrackPlacementStyleValue;
|
||||
class GridTrackSizeList;
|
||||
class GridTrackSizeListStyleValue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue