mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibWeb: Replace PlaceContentStyleValue with ShorthandStyleValue
This commit is contained in:
parent
6758decc74
commit
1b0939b418
Notes:
sideshowbarker
2024-07-17 09:56:35 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/1b0939b418 Pull-request: https://github.com/SerenityOS/serenity/pull/21168
10 changed files with 13 additions and 78 deletions
|
@ -27,7 +27,6 @@ source_set("StyleValues") {
|
|||
"MathDepthStyleValue.cpp",
|
||||
"NumberStyleValue.cpp",
|
||||
"OverflowStyleValue.cpp",
|
||||
"PlaceContentStyleValue.cpp",
|
||||
"PlaceItemsStyleValue.cpp",
|
||||
"PlaceSelfStyleValue.cpp",
|
||||
"PositionStyleValue.cpp",
|
||||
|
|
|
@ -104,7 +104,6 @@ set(SOURCES
|
|||
CSS/StyleValues/MathDepthStyleValue.cpp
|
||||
CSS/StyleValues/NumberStyleValue.cpp
|
||||
CSS/StyleValues/OverflowStyleValue.cpp
|
||||
CSS/StyleValues/PlaceContentStyleValue.cpp
|
||||
CSS/StyleValues/PlaceItemsStyleValue.cpp
|
||||
CSS/StyleValues/PlaceSelfStyleValue.cpp
|
||||
CSS/StyleValues/PositionStyleValue.cpp
|
||||
|
|
|
@ -61,7 +61,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
|
@ -4581,13 +4580,17 @@ RefPtr<StyleValue> Parser::parse_place_content_value(Vector<ComponentValue> cons
|
|||
if (component_values.size() == 1) {
|
||||
if (!property_accepts_identifier(PropertyID::JustifyContent, maybe_align_content_value->to_identifier()))
|
||||
return nullptr;
|
||||
return PlaceContentStyleValue::create(*maybe_align_content_value, *maybe_align_content_value);
|
||||
return ShorthandStyleValue::create(PropertyID::PlaceContent,
|
||||
{ PropertyID::AlignContent, PropertyID::JustifyContent },
|
||||
{ *maybe_align_content_value, *maybe_align_content_value });
|
||||
}
|
||||
|
||||
auto maybe_justify_content_value = parse_css_value_for_property(PropertyID::JustifyContent, tokens);
|
||||
if (!maybe_justify_content_value)
|
||||
return nullptr;
|
||||
return PlaceContentStyleValue::create(maybe_align_content_value.release_nonnull(), maybe_justify_content_value.release_nonnull());
|
||||
return ShorthandStyleValue::create(PropertyID::PlaceContent,
|
||||
{ PropertyID::AlignContent, PropertyID::JustifyContent },
|
||||
{ maybe_align_content_value.release_nonnull(), maybe_justify_content_value.release_nonnull() });
|
||||
}
|
||||
|
||||
RefPtr<StyleValue> Parser::parse_place_items_value(Vector<ComponentValue> const& component_values)
|
||||
|
|
|
@ -46,7 +46,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
|
@ -495,13 +494,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
|
|||
}
|
||||
|
||||
if (property_id == CSS::PropertyID::PlaceContent) {
|
||||
if (value.is_place_content()) {
|
||||
auto const& place_content = value.as_place_content();
|
||||
set_longhand_property(CSS::PropertyID::AlignContent, place_content.align_content());
|
||||
set_longhand_property(CSS::PropertyID::JustifyContent, place_content.justify_content());
|
||||
return;
|
||||
}
|
||||
|
||||
style.set_property(CSS::PropertyID::AlignContent, value);
|
||||
style.set_property(CSS::PropertyID::JustifyContent, value);
|
||||
return;
|
||||
|
|
|
@ -41,7 +41,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceItemsStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PlaceSelfStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
||||
|
|
|
@ -113,7 +113,6 @@ using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
|
|||
__ENUMERATE_STYLE_VALUE_TYPE(Number, number) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Overflow, overflow) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Percentage, percentage) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(PlaceContent, place_content) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(PlaceItems, place_items) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(PlaceSelf, place_self) \
|
||||
__ENUMERATE_STYLE_VALUE_TYPE(Position, position) \
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Hunter Salyer <thefalsehonesty@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "PlaceContentStyleValue.h"
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
String PlaceContentStyleValue::to_string() const
|
||||
{
|
||||
auto align_content = m_properties.align_content->to_string();
|
||||
auto justify_content = m_properties.justify_content->to_string();
|
||||
if (align_content == justify_content)
|
||||
return MUST(String::formatted("{}", align_content));
|
||||
return MUST(String::formatted("{} {}", align_content, justify_content));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Hunter Salyer <thefalsehonesty@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class PlaceContentStyleValue final : public StyleValueWithDefaultOperators<PlaceContentStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<PlaceContentStyleValue> create(ValueComparingNonnullRefPtr<StyleValue> align_content, ValueComparingNonnullRefPtr<StyleValue> justify_content)
|
||||
{
|
||||
return adopt_ref(*new (nothrow) PlaceContentStyleValue(move(align_content), move(justify_content)));
|
||||
}
|
||||
virtual ~PlaceContentStyleValue() override = default;
|
||||
|
||||
ValueComparingNonnullRefPtr<StyleValue> align_content() const { return m_properties.align_content; }
|
||||
ValueComparingNonnullRefPtr<StyleValue> justify_content() const { return m_properties.justify_content; }
|
||||
|
||||
virtual String to_string() const override;
|
||||
|
||||
bool properties_equal(PlaceContentStyleValue const& other) const { return m_properties == other.m_properties; }
|
||||
|
||||
private:
|
||||
PlaceContentStyleValue(ValueComparingNonnullRefPtr<StyleValue> align_content, ValueComparingNonnullRefPtr<StyleValue> justify_content)
|
||||
: StyleValueWithDefaultOperators(Type::PlaceContent)
|
||||
, m_properties { .align_content = move(align_content), .justify_content = move(justify_content) }
|
||||
{
|
||||
}
|
||||
|
||||
struct Properties {
|
||||
ValueComparingNonnullRefPtr<StyleValue> align_content;
|
||||
ValueComparingNonnullRefPtr<StyleValue> justify_content;
|
||||
bool operator==(Properties const&) const = default;
|
||||
} m_properties;
|
||||
};
|
||||
|
||||
}
|
|
@ -147,6 +147,13 @@ String ShorthandStyleValue::to_string() const
|
|||
}
|
||||
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: {
|
||||
auto align_content = longhand(PropertyID::AlignContent)->to_string();
|
||||
auto justify_content = longhand(PropertyID::JustifyContent)->to_string();
|
||||
if (align_content == justify_content)
|
||||
return align_content;
|
||||
return MUST(String::formatted("{} {}", align_content, justify_content));
|
||||
}
|
||||
default:
|
||||
StringBuilder builder;
|
||||
auto first = true;
|
||||
|
|
|
@ -139,7 +139,6 @@ class OverflowStyleValue;
|
|||
class Percentage;
|
||||
class PercentageOrCalculated;
|
||||
class PercentageStyleValue;
|
||||
class PlaceContentStyleValue;
|
||||
class PlaceItemsStyleValue;
|
||||
class PlaceSelfStyleValue;
|
||||
class PositionStyleValue;
|
||||
|
|
Loading…
Add table
Reference in a new issue