mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibWeb: Replace GridAreaShorthandStyleValue with ShorthandStyleValue
This commit is contained in:
parent
fe499681d9
commit
48f3603119
Notes:
sideshowbarker
2024-07-17 05:18:58 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/48f3603119 Pull-request: https://github.com/SerenityOS/serenity/pull/21168
11 changed files with 23 additions and 120 deletions
|
@ -14,7 +14,6 @@ source_set("StyleValues") {
|
|||
"EasingStyleValue.cpp",
|
||||
"EdgeStyleValue.cpp",
|
||||
"FilterValueListStyleValue.cpp",
|
||||
"GridAreaShorthandStyleValue.cpp",
|
||||
"GridAutoFlowStyleValue.cpp",
|
||||
"GridTemplateAreaStyleValue.cpp",
|
||||
"GridTrackPlacementShorthandStyleValue.cpp",
|
||||
|
|
|
@ -91,7 +91,6 @@ set(SOURCES
|
|||
CSS/StyleValues/EasingStyleValue.cpp
|
||||
CSS/StyleValues/EdgeStyleValue.cpp
|
||||
CSS/StyleValues/FilterValueListStyleValue.cpp
|
||||
CSS/StyleValues/GridAreaShorthandStyleValue.cpp
|
||||
CSS/StyleValues/GridAutoFlowStyleValue.cpp
|
||||
CSS/StyleValues/GridTemplateAreaStyleValue.cpp
|
||||
CSS/StyleValues/GridTrackPlacementStyleValue.cpp
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
|
||||
|
@ -5673,7 +5672,9 @@ RefPtr<StyleValue> Parser::parse_grid_area_shorthand_value(Vector<ComponentValue
|
|||
else
|
||||
column_end = row_end;
|
||||
|
||||
return GridAreaShorthandStyleValue::create(row_start, column_start, row_end, column_end);
|
||||
return ShorthandStyleValue::create(PropertyID::GridArea,
|
||||
{ PropertyID::GridRowStart, PropertyID::GridColumnStart, PropertyID::GridRowEnd, PropertyID::GridColumnEnd },
|
||||
{ GridTrackPlacementStyleValue::create(row_start), GridTrackPlacementStyleValue::create(column_start), GridTrackPlacementStyleValue::create(row_end), GridTrackPlacementStyleValue::create(column_end) });
|
||||
}
|
||||
|
||||
RefPtr<StyleValue> Parser::parse_grid_shorthand_value(Vector<ComponentValue> const& component_value)
|
||||
|
|
|
@ -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/GridAreaShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackSizeListShorthandStyleValue.h>
|
||||
|
@ -314,11 +313,9 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
|
|||
VERIFY(maybe_grid_column_end.value().value->is_grid_track_placement());
|
||||
grid_column_end = maybe_grid_column_end.value().value->as_grid_track_placement();
|
||||
}
|
||||
return GridAreaShorthandStyleValue::create(
|
||||
grid_row_start.release_nonnull(),
|
||||
grid_column_start.release_nonnull(),
|
||||
grid_row_end.release_nonnull(),
|
||||
grid_column_end.release_nonnull());
|
||||
return ShorthandStyleValue::create(property_id,
|
||||
{ PropertyID::GridRowStart, PropertyID::GridColumnStart, PropertyID::GridRowEnd, PropertyID::GridColumnEnd },
|
||||
{ grid_row_start.release_nonnull(), grid_column_start.release_nonnull(), grid_row_end.release_nonnull(), grid_column_end.release_nonnull() });
|
||||
}
|
||||
case PropertyID::GridColumn: {
|
||||
auto maybe_grid_column_end = property(PropertyID::GridColumnEnd);
|
||||
|
|
|
@ -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/GridAreaShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackSizeListShorthandStyleValue.h>
|
||||
|
@ -746,14 +745,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::GridArea) {
|
||||
if (value.is_grid_area_shorthand()) {
|
||||
auto const& shorthand = value.as_grid_area_shorthand();
|
||||
set_longhand_property(CSS::PropertyID::GridRowStart, shorthand.row_start());
|
||||
set_longhand_property(CSS::PropertyID::GridColumnStart, shorthand.column_start());
|
||||
set_longhand_property(CSS::PropertyID::GridRowEnd, shorthand.row_end());
|
||||
set_longhand_property(CSS::PropertyID::GridColumnEnd, shorthand.column_end());
|
||||
return;
|
||||
}
|
||||
set_longhand_property(CSS::PropertyID::GridRowStart, value);
|
||||
set_longhand_property(CSS::PropertyID::GridColumnStart, value);
|
||||
set_longhand_property(CSS::PropertyID::GridRowEnd, value);
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
|
||||
|
|
|
@ -97,7 +97,6 @@ using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
|
|||
__ENUMERATE_STYLE_VALUE_TYPE(Edge, edge) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(FilterValueList, filter_value_list) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Frequency, frequency) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(GridAreaShorthand, grid_area_shorthand) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(GridAutoFlow, grid_auto_flow) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(GridTemplateArea, grid_template_area) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(GridTrackPlacement, grid_track_placement) \
|
||||
|
|
|
@ -1,47 +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 "GridAreaShorthandStyleValue.h"
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> GridAreaShorthandStyleValue::create(
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start,
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start,
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end,
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) GridAreaShorthandStyleValue(row_start, column_start, row_end, column_end));
|
||||
}
|
||||
|
||||
ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> GridAreaShorthandStyleValue::create(GridTrackPlacement row_start, GridTrackPlacement column_start, GridTrackPlacement row_end, GridTrackPlacement column_end)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) GridAreaShorthandStyleValue(
|
||||
GridTrackPlacementStyleValue::create(row_start),
|
||||
GridTrackPlacementStyleValue::create(column_start),
|
||||
GridTrackPlacementStyleValue::create(row_end),
|
||||
GridTrackPlacementStyleValue::create(column_end)));
|
||||
}
|
||||
|
||||
String GridAreaShorthandStyleValue::to_string() const
|
||||
{
|
||||
StringBuilder builder;
|
||||
if (!m_properties.row_start->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
builder.appendff("{}", m_properties.row_start->as_grid_track_placement().grid_track_placement().to_string());
|
||||
if (!m_properties.column_start->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
builder.appendff(" / {}", m_properties.column_start->as_grid_track_placement().grid_track_placement().to_string());
|
||||
if (!m_properties.row_end->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
builder.appendff(" / {}", m_properties.row_end->as_grid_track_placement().grid_track_placement().to_string());
|
||||
if (!m_properties.column_end->as_grid_track_placement().grid_track_placement().is_auto())
|
||||
builder.appendff(" / {}", m_properties.column_end->as_grid_track_placement().grid_track_placement().to_string());
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,51 +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 GridAreaShorthandStyleValue final : public StyleValueWithDefaultOperators<GridAreaShorthandStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create(
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start,
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start,
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end,
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end);
|
||||
static ValueComparingNonnullRefPtr<GridAreaShorthandStyleValue> create(GridTrackPlacement row_start, GridTrackPlacement column_start, GridTrackPlacement row_end, GridTrackPlacement column_end);
|
||||
virtual ~GridAreaShorthandStyleValue() override = default;
|
||||
|
||||
auto row_start() const { return m_properties.row_start; }
|
||||
auto column_start() const { return m_properties.column_start; }
|
||||
auto row_end() const { return m_properties.row_end; }
|
||||
auto column_end() const { return m_properties.column_end; }
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
||||
bool properties_equal(GridAreaShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
GridAreaShorthandStyleValue(ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end, ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end)
|
||||
: StyleValueWithDefaultOperators(Type::GridAreaShorthand)
|
||||
, m_properties { .row_start = move(row_start), .column_start = move(column_start), .row_end = move(row_end), .column_end = move(column_end) }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_start;
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_start;
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> row_end;
|
||||
ValueComparingNonnullRefPtr<GridTrackPlacementStyleValue const> column_end;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
#include "ShorthandStyleValue.h"
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
@ -94,6 +95,22 @@ String ShorthandStyleValue::to_string() const
|
|||
return MUST(String::formatted("{} {} {}", longhand(PropertyID::FlexGrow)->to_string(), longhand(PropertyID::FlexShrink)->to_string(), longhand(PropertyID::FlexBasis)->to_string()));
|
||||
case PropertyID::FlexFlow:
|
||||
return MUST(String::formatted("{} {}", longhand(PropertyID::FlexDirection)->to_string(), longhand(PropertyID::FlexWrap)->to_string()));
|
||||
case PropertyID::GridArea: {
|
||||
auto& row_start = longhand(PropertyID::GridRowStart)->as_grid_track_placement();
|
||||
auto& column_start = longhand(PropertyID::GridColumnStart)->as_grid_track_placement();
|
||||
auto& row_end = longhand(PropertyID::GridRowEnd)->as_grid_track_placement();
|
||||
auto& column_end = longhand(PropertyID::GridColumnEnd)->as_grid_track_placement();
|
||||
StringBuilder builder;
|
||||
if (!row_start.grid_track_placement().is_auto())
|
||||
builder.appendff("{}", row_start.grid_track_placement().to_string());
|
||||
if (!column_start.grid_track_placement().is_auto())
|
||||
builder.appendff(" / {}", column_start.grid_track_placement().to_string());
|
||||
if (!row_end.grid_track_placement().is_auto())
|
||||
builder.appendff(" / {}", row_end.grid_track_placement().to_string());
|
||||
if (!column_end.grid_track_placement().is_auto())
|
||||
builder.appendff(" / {}", column_end.grid_track_placement().to_string());
|
||||
return MUST(builder.to_string());
|
||||
}
|
||||
default:
|
||||
StringBuilder builder;
|
||||
auto first = true;
|
||||
|
|
|
@ -106,7 +106,6 @@ class Frequency;
|
|||
class FrequencyOrCalculated;
|
||||
class FrequencyPercentage;
|
||||
class FrequencyStyleValue;
|
||||
class GridAreaShorthandStyleValue;
|
||||
class GridAutoFlowStyleValue;
|
||||
class GridMinMax;
|
||||
class GridRepeat;
|
||||
|
|
Loading…
Add table
Reference in a new issue