LibWeb: Replace BorderRadiusShorthandStyleValue with ShorthandStyleValue

This commit is contained in:
Sam Atkins 2023-09-19 16:01:44 +01:00 committed by Sam Atkins
parent 34e0899ab0
commit 34591549b1
Notes: sideshowbarker 2024-07-16 20:31:50 +09:00
11 changed files with 24 additions and 104 deletions

View File

@ -5,7 +5,6 @@ source_set("StyleValues") {
"AngleStyleValue.cpp",
"BackgroundRepeatStyleValue.cpp",
"BackgroundSizeStyleValue.cpp",
"BorderRadiusShorthandStyleValue.cpp",
"BorderRadiusStyleValue.cpp",
"BorderStyleValue.cpp",
"CalculatedStyleValue.cpp",

View File

@ -82,7 +82,6 @@ set(SOURCES
CSS/StyleValues/AngleStyleValue.cpp
CSS/StyleValues/BackgroundRepeatStyleValue.cpp
CSS/StyleValues/BackgroundSizeStyleValue.cpp
CSS/StyleValues/BorderRadiusShorthandStyleValue.cpp
CSS/StyleValues/BorderRadiusStyleValue.cpp
CSS/StyleValues/BorderStyleValue.cpp
CSS/StyleValues/CalculatedStyleValue.cpp

View File

@ -37,7 +37,6 @@
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
@ -3358,7 +3357,9 @@ RefPtr<StyleValue> Parser::parse_border_radius_shorthand_value(Vector<ComponentV
auto bottom_left_radius = BorderRadiusStyleValue::create(bottom_left(horizontal_radii),
vertical_radii.is_empty() ? bottom_left(horizontal_radii) : bottom_left(vertical_radii));
return BorderRadiusShorthandStyleValue::create(move(top_left_radius), move(top_right_radius), move(bottom_right_radius), move(bottom_left_radius));
return ShorthandStyleValue::create(PropertyID::BorderRadius,
{ PropertyID::BorderTopLeftRadius, PropertyID::BorderTopRightRadius, PropertyID::BorderBottomRightRadius, PropertyID::BorderBottomLeftRadius },
{ move(top_left_radius), move(top_right_radius), move(bottom_right_radius), move(bottom_left_radius) });
}
RefPtr<StyleValue> Parser::parse_shadow_value(Vector<ComponentValue> const& component_values, AllowInsetKeyword allow_inset_keyword)

View File

@ -14,7 +14,6 @@
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
@ -244,7 +243,9 @@ RefPtr<StyleValue const> ResolvedCSSStyleDeclaration::style_value_for_property(L
bottom_right_radius = maybe_bottom_right_radius.value().value->as_border_radius();
}
return BorderRadiusShorthandStyleValue::create(top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull());
return ShorthandStyleValue::create(property_id,
{ PropertyID::BorderTopLeftRadius, PropertyID::BorderTopRightRadius, PropertyID::BorderBottomRightRadius, PropertyID::BorderBottomLeftRadius },
{ top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull() });
}
case PropertyID::BorderRight: {
auto border = layout_node.computed_values().border_right();

View File

@ -30,7 +30,6 @@
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/CSS/StyleSheet.h>
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
@ -551,15 +550,6 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
}
if (property_id == CSS::PropertyID::BorderRadius) {
if (value.is_border_radius_shorthand()) {
auto const& shorthand = value.as_border_radius_shorthand();
set_longhand_property(CSS::PropertyID::BorderTopLeftRadius, shorthand.top_left());
set_longhand_property(CSS::PropertyID::BorderTopRightRadius, shorthand.top_right());
set_longhand_property(CSS::PropertyID::BorderBottomRightRadius, shorthand.bottom_right());
set_longhand_property(CSS::PropertyID::BorderBottomLeftRadius, shorthand.bottom_left());
return;
}
set_longhand_property(CSS::PropertyID::BorderTopLeftRadius, value);
set_longhand_property(CSS::PropertyID::BorderTopRightRadius, value);
set_longhand_property(CSS::PropertyID::BorderBottomRightRadius, value);

View File

@ -14,7 +14,6 @@
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>

View File

@ -88,7 +88,6 @@ using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
__ENUMERATE_STYLE_VALUE_TYPE(BackgroundSize, background_size) \
__ENUMERATE_STYLE_VALUE_TYPE(Border, border) \
__ENUMERATE_STYLE_VALUE_TYPE(BorderRadius, border_radius) \
__ENUMERATE_STYLE_VALUE_TYPE(BorderRadiusShorthand, border_radius_shorthand) \
__ENUMERATE_STYLE_VALUE_TYPE(Calculated, calculated) \
__ENUMERATE_STYLE_VALUE_TYPE(Color, color) \
__ENUMERATE_STYLE_VALUE_TYPE(ConicGradient, conic_gradient) \

View File

@ -1,27 +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 "BorderRadiusShorthandStyleValue.h"
namespace Web::CSS {
String BorderRadiusShorthandStyleValue::to_string() const
{
return MUST(String::formatted("{} {} {} {} / {} {} {} {}",
m_properties.top_left->horizontal_radius().to_string(),
m_properties.top_right->horizontal_radius().to_string(),
m_properties.bottom_right->horizontal_radius().to_string(),
m_properties.bottom_left->horizontal_radius().to_string(),
m_properties.top_left->vertical_radius().to_string(),
m_properties.top_right->vertical_radius().to_string(),
m_properties.bottom_right->vertical_radius().to_string(),
m_properties.bottom_left->vertical_radius().to_string()));
}
}

View File

@ -1,58 +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>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
namespace Web::CSS {
class BorderRadiusShorthandStyleValue final : public StyleValueWithDefaultOperators<BorderRadiusShorthandStyleValue> {
public:
static ValueComparingNonnullRefPtr<BorderRadiusShorthandStyleValue> create(
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
{
return adopt_ref(*new (nothrow) BorderRadiusShorthandStyleValue(move(top_left), move(top_right), move(bottom_right), move(bottom_left)));
}
virtual ~BorderRadiusShorthandStyleValue() override = default;
auto top_left() const { return m_properties.top_left; }
auto top_right() const { return m_properties.top_right; }
auto bottom_right() const { return m_properties.bottom_right; }
auto bottom_left() const { return m_properties.bottom_left; }
virtual String to_string() const override;
bool properties_equal(BorderRadiusShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
private:
BorderRadiusShorthandStyleValue(
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right,
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left)
: StyleValueWithDefaultOperators(Type::BorderRadiusShorthand)
, m_properties { .top_left = move(top_left), .top_right = move(top_right), .bottom_right = move(bottom_right), .bottom_left = move(bottom_left) }
{
}
struct Properties {
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_left;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> top_right;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_right;
ValueComparingNonnullRefPtr<BorderRadiusStyleValue const> bottom_left;
bool operator==(Properties const&) const = default;
} m_properties;
};
}

View File

@ -1,11 +1,13 @@
/*
* Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ShorthandStyleValue.h"
#include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
namespace Web::CSS {
@ -72,6 +74,22 @@ String ShorthandStyleValue::to_string() const
return MUST(builder.to_string());
}
case PropertyID::BorderRadius: {
auto& top_left = longhand(PropertyID::BorderTopLeftRadius)->as_border_radius();
auto& top_right = longhand(PropertyID::BorderTopRightRadius)->as_border_radius();
auto& bottom_right = longhand(PropertyID::BorderBottomRightRadius)->as_border_radius();
auto& bottom_left = longhand(PropertyID::BorderBottomLeftRadius)->as_border_radius();
return MUST(String::formatted("{} {} {} {} / {} {} {} {}",
top_left.horizontal_radius().to_string(),
top_right.horizontal_radius().to_string(),
bottom_right.horizontal_radius().to_string(),
bottom_left.horizontal_radius().to_string(),
top_left.vertical_radius().to_string(),
top_right.vertical_radius().to_string(),
bottom_right.vertical_radius().to_string(),
bottom_left.vertical_radius().to_string()));
}
case PropertyID::Flex:
return MUST(String::formatted("{} {} {}", longhand(PropertyID::FlexGrow)->to_string(), longhand(PropertyID::FlexShrink)->to_string(), longhand(PropertyID::FlexBasis)->to_string()));
case PropertyID::FlexFlow:

View File

@ -74,7 +74,6 @@ class AnglePercentage;
class AngleStyleValue;
class BackgroundRepeatStyleValue;
class BackgroundSizeStyleValue;
class BorderRadiusShorthandStyleValue;
class BorderRadiusStyleValue;
class BorderStyleValue;
class CSSConditionRule;