2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2022-11-08 16:31:01 +00:00
|
|
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
2022-01-24 17:38:29 +00:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
2023-01-13 23:44:44 +00:00
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2020-03-07 10:32:51 +01:00
|
|
|
#include <LibWeb/CSS/StyleValue.h>
|
2023-03-24 16:42:50 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
2023-03-23 17:26:13 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
|
2023-03-23 17:44:13 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/BackgroundRepeatStyleValue.h>
|
2023-03-23 17:54:05 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
2023-03-23 17:35:44 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/BackgroundStyleValue.h>
|
2023-03-25 00:29:33 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/BorderRadiusShorthandStyleValue.h>
|
2023-03-25 00:33:20 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
2023-03-23 20:56:30 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/BorderStyleValue.h>
|
2023-03-30 17:34:14 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
2023-03-23 21:12:15 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
2023-03-24 16:09:41 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
2023-03-23 21:17:43 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
2023-04-02 22:56:45 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
2023-03-23 21:26:03 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
2023-03-23 21:39:08 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/FlexFlowStyleValue.h>
|
2023-03-23 21:33:13 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
2023-03-23 21:44:40 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/FontStyleValue.h>
|
2023-03-23 21:50:24 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
2023-03-24 14:48:19 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridAreaShorthandStyleValue.h>
|
2023-03-24 14:25:00 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
2023-03-24 14:50:50 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTrackPlacementShorthandStyleValue.h>
|
2023-03-24 14:53:08 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
2023-03-24 14:57:27 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTrackSizeStyleValue.h>
|
2023-03-24 15:04:24 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/IdentifierStyleValue.h>
|
2023-03-24 15:17:11 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
2023-03-24 16:45:58 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/InheritStyleValue.h>
|
2023-03-24 16:55:44 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/InitialStyleValue.h>
|
2023-03-24 17:04:04 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
2023-03-24 16:17:50 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/LinearGradientStyleValue.h>
|
2023-03-24 17:07:57 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ListStyleStyleValue.h>
|
2023-03-24 17:16:07 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/NumericStyleValue.h>
|
2023-03-24 17:20:16 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/OverflowStyleValue.h>
|
2023-03-24 17:28:43 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
2023-03-24 17:35:31 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
2023-03-24 16:35:18 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
|
2023-03-25 00:02:50 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
|
2023-03-24 17:40:28 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
|
2023-03-24 17:45:25 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
|
2023-03-24 17:48:42 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
|
2023-03-25 00:12:21 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
2023-03-24 17:52:37 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h>
|
2023-03-24 23:47:56 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
2023-03-24 17:59:33 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
2023-04-20 18:31:00 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
2023-03-24 23:53:41 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
2023-03-24 23:56:56 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/UnsetStyleValue.h>
|
2019-06-22 21:48:21 +02:00
|
|
|
|
2020-07-26 20:01:35 +02:00
|
|
|
namespace Web::CSS {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2019-06-22 21:48:21 +02:00
|
|
|
StyleValue::StyleValue(Type type)
|
|
|
|
: m_type(type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-07-31 01:11:59 +01:00
|
|
|
AbstractImageStyleValue const& StyleValue::as_abstract_image() const
|
|
|
|
{
|
|
|
|
VERIFY(is_abstract_image());
|
|
|
|
return static_cast<AbstractImageStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-02-21 17:43:30 +00:00
|
|
|
AngleStyleValue const& StyleValue::as_angle() const
|
|
|
|
{
|
|
|
|
VERIFY(is_angle());
|
|
|
|
return static_cast<AngleStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
BackgroundStyleValue const& StyleValue::as_background() const
|
2021-09-22 12:42:54 +01:00
|
|
|
{
|
2021-09-23 19:54:19 +01:00
|
|
|
VERIFY(is_background());
|
|
|
|
return static_cast<BackgroundStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundRepeatStyleValue const& StyleValue::as_background_repeat() const
|
|
|
|
{
|
|
|
|
VERIFY(is_background_repeat());
|
|
|
|
return static_cast<BackgroundRepeatStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-11-05 12:18:23 +00:00
|
|
|
BackgroundSizeStyleValue const& StyleValue::as_background_size() const
|
|
|
|
{
|
|
|
|
VERIFY(is_background_size());
|
|
|
|
return static_cast<BackgroundSizeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
BorderStyleValue const& StyleValue::as_border() const
|
|
|
|
{
|
|
|
|
VERIFY(is_border());
|
|
|
|
return static_cast<BorderStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
BorderRadiusStyleValue const& StyleValue::as_border_radius() const
|
|
|
|
{
|
|
|
|
VERIFY(is_border_radius());
|
|
|
|
return static_cast<BorderRadiusStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-04-18 17:04:38 +01:00
|
|
|
BorderRadiusShorthandStyleValue const& StyleValue::as_border_radius_shorthand() const
|
|
|
|
{
|
|
|
|
VERIFY(is_border_radius_shorthand());
|
|
|
|
return static_cast<BorderRadiusShorthandStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-03-23 16:55:22 +00:00
|
|
|
ShadowStyleValue const& StyleValue::as_shadow() const
|
2021-09-23 19:54:19 +01:00
|
|
|
{
|
2022-03-23 16:55:22 +00:00
|
|
|
VERIFY(is_shadow());
|
|
|
|
return static_cast<ShadowStyleValue const&>(*this);
|
2021-09-23 19:54:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
CalculatedStyleValue const& StyleValue::as_calculated() const
|
|
|
|
{
|
|
|
|
VERIFY(is_calculated());
|
|
|
|
return static_cast<CalculatedStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorStyleValue const& StyleValue::as_color() const
|
|
|
|
{
|
|
|
|
VERIFY(is_color());
|
|
|
|
return static_cast<ColorStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-10-28 20:44:00 +01:00
|
|
|
ConicGradientStyleValue const& StyleValue::as_conic_gradient() const
|
|
|
|
{
|
|
|
|
VERIFY(is_conic_gradient());
|
|
|
|
return static_cast<ConicGradientStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-02-23 19:56:25 +00:00
|
|
|
ContentStyleValue const& StyleValue::as_content() const
|
|
|
|
{
|
|
|
|
VERIFY(is_content());
|
|
|
|
return static_cast<ContentStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2023-04-02 22:56:45 +01:00
|
|
|
EdgeStyleValue const& StyleValue::as_edge() const
|
|
|
|
{
|
|
|
|
VERIFY(is_edge());
|
|
|
|
return static_cast<EdgeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-09-15 08:31:14 +01:00
|
|
|
FilterValueListStyleValue const& StyleValue::as_filter_value_list() const
|
|
|
|
{
|
|
|
|
VERIFY(is_filter_value_list());
|
|
|
|
return static_cast<FilterValueListStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
FlexStyleValue const& StyleValue::as_flex() const
|
|
|
|
{
|
|
|
|
VERIFY(is_flex());
|
|
|
|
return static_cast<FlexStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
FlexFlowStyleValue const& StyleValue::as_flex_flow() const
|
|
|
|
{
|
|
|
|
VERIFY(is_flex_flow());
|
|
|
|
return static_cast<FlexFlowStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
FontStyleValue const& StyleValue::as_font() const
|
|
|
|
{
|
|
|
|
VERIFY(is_font());
|
|
|
|
return static_cast<FontStyleValue const&>(*this);
|
|
|
|
}
|
2021-09-22 12:42:54 +01:00
|
|
|
|
2022-02-21 17:49:47 +00:00
|
|
|
FrequencyStyleValue const& StyleValue::as_frequency() const
|
|
|
|
{
|
|
|
|
VERIFY(is_frequency());
|
|
|
|
return static_cast<FrequencyStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-08-24 12:25:56 +02:00
|
|
|
GridTrackPlacementShorthandStyleValue const& StyleValue::as_grid_track_placement_shorthand() const
|
|
|
|
{
|
|
|
|
VERIFY(is_grid_track_placement_shorthand());
|
|
|
|
return static_cast<GridTrackPlacementShorthandStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2023-01-16 19:02:39 +01:00
|
|
|
GridAreaShorthandStyleValue const& StyleValue::as_grid_area_shorthand() const
|
|
|
|
{
|
|
|
|
VERIFY(is_grid_area_shorthand());
|
|
|
|
return static_cast<GridAreaShorthandStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2023-01-16 18:17:05 +01:00
|
|
|
GridTemplateAreaStyleValue const& StyleValue::as_grid_template_area() const
|
|
|
|
{
|
|
|
|
VERIFY(is_grid_template_area());
|
|
|
|
return static_cast<GridTemplateAreaStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-08-24 12:31:00 +02:00
|
|
|
GridTrackPlacementStyleValue const& StyleValue::as_grid_track_placement() const
|
|
|
|
{
|
|
|
|
VERIFY(is_grid_track_placement());
|
|
|
|
return static_cast<GridTrackPlacementStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
IdentifierStyleValue const& StyleValue::as_identifier() const
|
|
|
|
{
|
|
|
|
VERIFY(is_identifier());
|
|
|
|
return static_cast<IdentifierStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImageStyleValue const& StyleValue::as_image() const
|
|
|
|
{
|
|
|
|
VERIFY(is_image());
|
|
|
|
return static_cast<ImageStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
InheritStyleValue const& StyleValue::as_inherit() const
|
|
|
|
{
|
|
|
|
VERIFY(is_inherit());
|
|
|
|
return static_cast<InheritStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
InitialStyleValue const& StyleValue::as_initial() const
|
|
|
|
{
|
|
|
|
VERIFY(is_initial());
|
|
|
|
return static_cast<InitialStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
LengthStyleValue const& StyleValue::as_length() const
|
|
|
|
{
|
|
|
|
VERIFY(is_length());
|
|
|
|
return static_cast<LengthStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-10-30 13:27:57 +01:00
|
|
|
GridTrackSizeStyleValue const& StyleValue::as_grid_track_size_list() const
|
2022-08-24 12:27:56 +02:00
|
|
|
{
|
2022-10-30 13:27:57 +01:00
|
|
|
VERIFY(is_grid_track_size_list());
|
2022-08-24 12:27:56 +02:00
|
|
|
return static_cast<GridTrackSizeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-07-12 00:09:29 +01:00
|
|
|
LinearGradientStyleValue const& StyleValue::as_linear_gradient() const
|
|
|
|
{
|
|
|
|
VERIFY(is_linear_gradient());
|
|
|
|
return static_cast<LinearGradientStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
ListStyleStyleValue const& StyleValue::as_list_style() const
|
|
|
|
{
|
|
|
|
VERIFY(is_list_style());
|
|
|
|
return static_cast<ListStyleStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
NumericStyleValue const& StyleValue::as_numeric() const
|
|
|
|
{
|
|
|
|
VERIFY(is_numeric());
|
|
|
|
return static_cast<NumericStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
OverflowStyleValue const& StyleValue::as_overflow() const
|
|
|
|
{
|
|
|
|
VERIFY(is_overflow());
|
|
|
|
return static_cast<OverflowStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-01-14 17:09:02 +00:00
|
|
|
PercentageStyleValue const& StyleValue::as_percentage() const
|
|
|
|
{
|
|
|
|
VERIFY(is_percentage());
|
|
|
|
return static_cast<PercentageStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-10-31 16:02:29 +00:00
|
|
|
PositionStyleValue const& StyleValue::as_position() const
|
|
|
|
{
|
|
|
|
VERIFY(is_position());
|
|
|
|
return static_cast<PositionStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-11-11 18:13:00 +01:00
|
|
|
RadialGradientStyleValue const& StyleValue::as_radial_gradient() const
|
|
|
|
{
|
|
|
|
VERIFY(is_radial_gradient());
|
|
|
|
return static_cast<RadialGradientStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-07-31 18:46:35 +02:00
|
|
|
RectStyleValue const& StyleValue::as_rect() const
|
|
|
|
{
|
|
|
|
VERIFY(is_rect());
|
|
|
|
return static_cast<RectStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-02-21 17:51:01 +00:00
|
|
|
ResolutionStyleValue const& StyleValue::as_resolution() const
|
|
|
|
{
|
|
|
|
VERIFY(is_resolution());
|
|
|
|
return static_cast<ResolutionStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
StringStyleValue const& StyleValue::as_string() const
|
|
|
|
{
|
|
|
|
VERIFY(is_string());
|
|
|
|
return static_cast<StringStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
TextDecorationStyleValue const& StyleValue::as_text_decoration() const
|
|
|
|
{
|
|
|
|
VERIFY(is_text_decoration());
|
|
|
|
return static_cast<TextDecorationStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2022-02-21 19:29:43 +00:00
|
|
|
TimeStyleValue const& StyleValue::as_time() const
|
|
|
|
{
|
|
|
|
VERIFY(is_time());
|
|
|
|
return static_cast<TimeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
TransformationStyleValue const& StyleValue::as_transformation() const
|
|
|
|
{
|
|
|
|
VERIFY(is_transformation());
|
|
|
|
return static_cast<TransformationStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-12-03 12:28:14 +00:00
|
|
|
UnresolvedStyleValue const& StyleValue::as_unresolved() const
|
|
|
|
{
|
|
|
|
VERIFY(is_unresolved());
|
|
|
|
return static_cast<UnresolvedStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
UnsetStyleValue const& StyleValue::as_unset() const
|
|
|
|
{
|
|
|
|
VERIFY(is_unset());
|
|
|
|
return static_cast<UnsetStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2023-04-20 18:31:00 +01:00
|
|
|
URLStyleValue const& StyleValue::as_url() const
|
|
|
|
{
|
|
|
|
VERIFY(is_url());
|
|
|
|
return static_cast<URLStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2021-09-23 19:54:19 +01:00
|
|
|
StyleValueList const& StyleValue::as_value_list() const
|
|
|
|
{
|
|
|
|
VERIFY(is_value_list());
|
|
|
|
return static_cast<StyleValueList const&>(*this);
|
|
|
|
}
|
|
|
|
|
2023-04-28 16:29:12 +01:00
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> StyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const
|
2023-03-31 14:25:38 +01:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2023-04-19 12:00:38 +01:00
|
|
|
bool StyleValue::has_auto() const
|
|
|
|
{
|
|
|
|
return is_identifier() && as_identifier().id() == ValueID::Auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueID StyleValue::to_identifier() const
|
|
|
|
{
|
|
|
|
if (is_identifier())
|
|
|
|
return as_identifier().id();
|
|
|
|
return ValueID::Invalid;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|