2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2023-05-24 16:28:09 +03:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
2021-08-09 22:28:56 +03:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
2022-11-08 19:31:01 +03:00
|
|
|
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
2023-01-14 02:44:44 +03:00
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-06-21 00:25:25 +03:00
|
|
|
#pragma once
|
|
|
|
|
2023-02-20 03:41:51 +03:00
|
|
|
#include <AK/Concepts.h>
|
2022-07-31 03:11:59 +03:00
|
|
|
#include <AK/GenericShorthands.h>
|
2021-07-23 00:01:39 +03:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
2019-06-21 19:58:45 +03:00
|
|
|
#include <AK/RefCounted.h>
|
2019-06-22 22:48:21 +03:00
|
|
|
#include <AK/RefPtr.h>
|
2023-01-06 21:02:26 +03:00
|
|
|
#include <AK/String.h>
|
2019-06-22 22:48:21 +03:00
|
|
|
#include <AK/StringView.h>
|
2019-10-19 12:49:46 +03:00
|
|
|
#include <AK/URL.h>
|
2021-07-23 00:01:39 +03:00
|
|
|
#include <AK/Variant.h>
|
|
|
|
#include <AK/Vector.h>
|
2019-10-19 12:49:46 +03:00
|
|
|
#include <AK/WeakPtr.h>
|
2022-03-06 20:17:50 +03:00
|
|
|
#include <LibGfx/Painter.h>
|
2022-04-13 19:29:01 +03:00
|
|
|
#include <LibWeb/CSS/Enums.h>
|
2020-03-07 12:32:51 +03:00
|
|
|
#include <LibWeb/CSS/Length.h>
|
2020-12-15 22:39:09 +03:00
|
|
|
#include <LibWeb/CSS/ValueID.h>
|
2020-07-21 17:23:08 +03:00
|
|
|
#include <LibWeb/Forward.h>
|
2019-06-21 00:25:25 +03:00
|
|
|
|
2020-07-21 17:23:08 +03:00
|
|
|
namespace Web::CSS {
|
2019-10-06 11:25:08 +03:00
|
|
|
|
2023-02-20 03:41:51 +03:00
|
|
|
template<typename T>
|
|
|
|
struct ValueComparingNonnullRefPtr : public NonnullRefPtr<T> {
|
|
|
|
using NonnullRefPtr<T>::NonnullRefPtr;
|
|
|
|
|
|
|
|
ValueComparingNonnullRefPtr(NonnullRefPtr<T> const& other)
|
|
|
|
: NonnullRefPtr<T>(other)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueComparingNonnullRefPtr(NonnullRefPtr<T>&& other)
|
|
|
|
: NonnullRefPtr<T>(move(other))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(ValueComparingNonnullRefPtr const& other) const
|
|
|
|
{
|
|
|
|
return this->ptr() == other.ptr() || this->ptr()->equals(*other);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
using NonnullRefPtr<T>::operator==;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct ValueComparingRefPtr : public RefPtr<T> {
|
|
|
|
using RefPtr<T>::RefPtr;
|
|
|
|
|
|
|
|
ValueComparingRefPtr(RefPtr<T> const& other)
|
|
|
|
: RefPtr<T>(other)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ValueComparingRefPtr(RefPtr<T>&& other)
|
|
|
|
: RefPtr<T>(move(other))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename U>
|
|
|
|
bool operator==(ValueComparingNonnullRefPtr<U> const& other) const
|
|
|
|
{
|
|
|
|
return this->ptr() == other.ptr() || (this->ptr() && this->ptr()->equals(*other));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(ValueComparingRefPtr const& other) const
|
|
|
|
{
|
|
|
|
return this->ptr() == other.ptr() || (this->ptr() && other.ptr() && this->ptr()->equals(*other));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
using RefPtr<T>::operator==;
|
|
|
|
};
|
|
|
|
|
2023-03-06 16:33:11 +03:00
|
|
|
using StyleValueVector = Vector<ValueComparingNonnullRefPtr<StyleValue const>>;
|
2023-02-20 03:41:51 +03:00
|
|
|
|
2019-06-21 16:29:31 +03:00
|
|
|
class StyleValue : public RefCounted<StyleValue> {
|
2019-06-21 00:25:25 +03:00
|
|
|
public:
|
2022-03-14 22:21:51 +03:00
|
|
|
virtual ~StyleValue() = default;
|
2019-06-21 00:25:25 +03:00
|
|
|
|
2019-07-03 08:55:22 +03:00
|
|
|
enum class Type {
|
2022-02-21 20:43:30 +03:00
|
|
|
Angle,
|
2021-08-03 16:56:08 +03:00
|
|
|
Background,
|
2021-08-10 12:21:42 +03:00
|
|
|
BackgroundRepeat,
|
2021-11-05 15:18:23 +03:00
|
|
|
BackgroundSize,
|
2021-08-05 23:11:38 +03:00
|
|
|
Border,
|
2021-08-06 18:55:08 +03:00
|
|
|
BorderRadius,
|
2022-04-18 19:02:39 +03:00
|
|
|
BorderRadiusShorthand,
|
2021-09-23 18:30:40 +03:00
|
|
|
Calculated,
|
|
|
|
Color,
|
2022-10-28 22:44:00 +03:00
|
|
|
ConicGradient,
|
2022-02-23 22:56:25 +03:00
|
|
|
Content,
|
2023-04-26 22:05:38 +03:00
|
|
|
Display,
|
2023-04-03 00:56:45 +03:00
|
|
|
Edge,
|
2022-09-15 10:31:14 +03:00
|
|
|
FilterValueList,
|
2021-08-04 19:48:08 +03:00
|
|
|
Flex,
|
2021-08-05 19:19:29 +03:00
|
|
|
FlexFlow,
|
2021-08-03 13:37:24 +03:00
|
|
|
Font,
|
2022-02-21 20:49:47 +03:00
|
|
|
Frequency,
|
2023-01-16 21:02:39 +03:00
|
|
|
GridAreaShorthand,
|
2023-01-16 20:17:05 +03:00
|
|
|
GridTemplateArea,
|
2022-08-24 13:31:00 +03:00
|
|
|
GridTrackPlacement,
|
2022-08-24 13:25:56 +03:00
|
|
|
GridTrackPlacementShorthand,
|
2022-10-30 15:27:57 +03:00
|
|
|
GridTrackSizeList,
|
2023-04-29 20:32:56 +03:00
|
|
|
GridTrackSizeListShorthand,
|
2021-09-23 18:30:40 +03:00
|
|
|
Identifier,
|
|
|
|
Image,
|
|
|
|
Inherit,
|
|
|
|
Initial,
|
|
|
|
Invalid,
|
|
|
|
Length,
|
2022-07-12 02:09:29 +03:00
|
|
|
LinearGradient,
|
2021-08-03 17:56:51 +03:00
|
|
|
ListStyle,
|
2021-09-23 18:30:40 +03:00
|
|
|
Numeric,
|
2021-08-09 16:54:40 +03:00
|
|
|
Overflow,
|
2022-01-14 20:09:02 +03:00
|
|
|
Percentage,
|
2021-10-31 19:02:29 +03:00
|
|
|
Position,
|
2022-11-11 20:13:00 +03:00
|
|
|
RadialGradient,
|
2022-07-31 19:46:35 +03:00
|
|
|
Rect,
|
2022-02-21 20:51:01 +03:00
|
|
|
Resolution,
|
2022-03-23 19:55:22 +03:00
|
|
|
Shadow,
|
2021-09-23 18:30:40 +03:00
|
|
|
String,
|
2021-08-04 14:34:14 +03:00
|
|
|
TextDecoration,
|
2022-02-21 22:29:43 +03:00
|
|
|
Time,
|
2021-09-18 18:20:00 +03:00
|
|
|
Transformation,
|
2021-12-03 15:28:14 +03:00
|
|
|
Unresolved,
|
2021-09-23 18:30:40 +03:00
|
|
|
Unset,
|
2023-04-20 20:31:00 +03:00
|
|
|
Url,
|
2022-07-12 02:09:29 +03:00
|
|
|
ValueList
|
2019-06-21 00:25:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Type type() const { return m_type; }
|
|
|
|
|
2022-11-11 20:13:00 +03:00
|
|
|
bool is_abstract_image() const { return AK::first_is_one_of(type(), Type::Image, Type::LinearGradient, Type::ConicGradient, Type::RadialGradient); }
|
2022-02-21 20:43:30 +03:00
|
|
|
bool is_angle() const { return type() == Type::Angle; }
|
2021-08-03 16:56:08 +03:00
|
|
|
bool is_background() const { return type() == Type::Background; }
|
2021-08-10 12:21:42 +03:00
|
|
|
bool is_background_repeat() const { return type() == Type::BackgroundRepeat; }
|
2021-11-05 15:18:23 +03:00
|
|
|
bool is_background_size() const { return type() == Type::BackgroundSize; }
|
2021-08-05 23:11:38 +03:00
|
|
|
bool is_border() const { return type() == Type::Border; }
|
2021-08-06 18:55:08 +03:00
|
|
|
bool is_border_radius() const { return type() == Type::BorderRadius; }
|
2022-04-18 19:04:38 +03:00
|
|
|
bool is_border_radius_shorthand() const { return type() == Type::BorderRadiusShorthand; }
|
2021-09-23 18:30:40 +03:00
|
|
|
bool is_calculated() const { return type() == Type::Calculated; }
|
|
|
|
bool is_color() const { return type() == Type::Color; }
|
2022-10-28 22:44:00 +03:00
|
|
|
bool is_conic_gradient() const { return type() == Type::ConicGradient; }
|
2022-02-23 22:56:25 +03:00
|
|
|
bool is_content() const { return type() == Type::Content; }
|
2023-04-26 22:05:38 +03:00
|
|
|
bool is_display() const { return type() == Type::Display; }
|
2023-04-03 00:56:45 +03:00
|
|
|
bool is_edge() const { return type() == Type::Edge; }
|
2022-09-15 10:31:14 +03:00
|
|
|
bool is_filter_value_list() const { return type() == Type::FilterValueList; }
|
2021-08-04 19:48:08 +03:00
|
|
|
bool is_flex() const { return type() == Type::Flex; }
|
2021-08-05 19:19:29 +03:00
|
|
|
bool is_flex_flow() const { return type() == Type::FlexFlow; }
|
2021-08-03 13:37:24 +03:00
|
|
|
bool is_font() const { return type() == Type::Font; }
|
2022-02-21 20:49:47 +03:00
|
|
|
bool is_frequency() const { return type() == Type::Frequency; }
|
2023-01-16 21:02:39 +03:00
|
|
|
bool is_grid_area_shorthand() const { return type() == Type::GridAreaShorthand; }
|
2023-01-16 20:17:05 +03:00
|
|
|
bool is_grid_template_area() const { return type() == Type::GridTemplateArea; }
|
2022-08-24 13:31:00 +03:00
|
|
|
bool is_grid_track_placement() const { return type() == Type::GridTrackPlacement; }
|
2022-08-24 13:25:56 +03:00
|
|
|
bool is_grid_track_placement_shorthand() const { return type() == Type::GridTrackPlacementShorthand; }
|
2022-10-30 15:27:57 +03:00
|
|
|
bool is_grid_track_size_list() const { return type() == Type::GridTrackSizeList; }
|
2023-04-29 20:32:56 +03:00
|
|
|
bool is_grid_track_size_list_shorthand() const { return type() == Type::GridTrackSizeListShorthand; }
|
2021-09-23 21:54:19 +03:00
|
|
|
bool is_identifier() const { return type() == Type::Identifier; }
|
2021-09-23 18:30:40 +03:00
|
|
|
bool is_image() const { return type() == Type::Image; }
|
|
|
|
bool is_inherit() const { return type() == Type::Inherit; }
|
|
|
|
bool is_initial() const { return type() == Type::Initial; }
|
2021-09-23 21:54:19 +03:00
|
|
|
bool is_length() const { return type() == Type::Length; }
|
2022-07-12 02:09:29 +03:00
|
|
|
bool is_linear_gradient() const { return type() == Type::LinearGradient; }
|
2021-08-03 17:56:51 +03:00
|
|
|
bool is_list_style() const { return type() == Type::ListStyle; }
|
2021-09-23 18:30:40 +03:00
|
|
|
bool is_numeric() const { return type() == Type::Numeric; }
|
2021-08-09 16:54:40 +03:00
|
|
|
bool is_overflow() const { return type() == Type::Overflow; }
|
2022-01-14 20:09:02 +03:00
|
|
|
bool is_percentage() const { return type() == Type::Percentage; }
|
2021-10-31 19:02:29 +03:00
|
|
|
bool is_position() const { return type() == Type::Position; }
|
2022-11-11 20:13:00 +03:00
|
|
|
bool is_radial_gradient() const { return type() == Type::RadialGradient; }
|
2022-07-31 19:46:35 +03:00
|
|
|
bool is_rect() const { return type() == Type::Rect; }
|
2022-02-21 20:51:01 +03:00
|
|
|
bool is_resolution() const { return type() == Type::Resolution; }
|
2022-03-23 19:55:22 +03:00
|
|
|
bool is_shadow() const { return type() == Type::Shadow; }
|
2021-09-23 18:30:40 +03:00
|
|
|
bool is_string() const { return type() == Type::String; }
|
2021-08-04 14:34:14 +03:00
|
|
|
bool is_text_decoration() const { return type() == Type::TextDecoration; }
|
2022-02-21 22:29:43 +03:00
|
|
|
bool is_time() const { return type() == Type::Time; }
|
2021-09-18 18:20:00 +03:00
|
|
|
bool is_transformation() const { return type() == Type::Transformation; }
|
2021-12-03 15:28:14 +03:00
|
|
|
bool is_unresolved() const { return type() == Type::Unresolved; }
|
2021-09-23 18:30:40 +03:00
|
|
|
bool is_unset() const { return type() == Type::Unset; }
|
2023-04-20 20:31:00 +03:00
|
|
|
bool is_url() const { return type() == Type::Url; }
|
2021-09-23 18:30:40 +03:00
|
|
|
bool is_value_list() const { return type() == Type::ValueList; }
|
2021-07-18 19:12:23 +03:00
|
|
|
|
2021-08-20 21:52:36 +03:00
|
|
|
bool is_builtin() const { return is_inherit() || is_initial() || is_unset(); }
|
2021-08-10 14:23:27 +03:00
|
|
|
|
2022-07-31 03:11:59 +03:00
|
|
|
AbstractImageStyleValue const& as_abstract_image() const;
|
2022-02-21 20:43:30 +03:00
|
|
|
AngleStyleValue const& as_angle() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
BackgroundStyleValue const& as_background() const;
|
2021-10-31 19:02:29 +03:00
|
|
|
BackgroundRepeatStyleValue const& as_background_repeat() const;
|
2021-11-05 15:18:23 +03:00
|
|
|
BackgroundSizeStyleValue const& as_background_size() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
BorderRadiusStyleValue const& as_border_radius() const;
|
2022-04-18 19:04:38 +03:00
|
|
|
BorderRadiusShorthandStyleValue const& as_border_radius_shorthand() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
BorderStyleValue const& as_border() const;
|
|
|
|
CalculatedStyleValue const& as_calculated() const;
|
|
|
|
ColorStyleValue const& as_color() const;
|
2022-10-28 22:44:00 +03:00
|
|
|
ConicGradientStyleValue const& as_conic_gradient() const;
|
2022-02-23 22:56:25 +03:00
|
|
|
ContentStyleValue const& as_content() const;
|
2023-04-26 22:05:38 +03:00
|
|
|
DisplayStyleValue const& as_display() const;
|
2023-04-03 00:56:45 +03:00
|
|
|
EdgeStyleValue const& as_edge() const;
|
2022-09-15 10:31:14 +03:00
|
|
|
FilterValueListStyleValue const& as_filter_value_list() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
FlexFlowStyleValue const& as_flex_flow() const;
|
|
|
|
FlexStyleValue const& as_flex() const;
|
|
|
|
FontStyleValue const& as_font() const;
|
2022-02-21 20:49:47 +03:00
|
|
|
FrequencyStyleValue const& as_frequency() const;
|
2023-01-16 21:02:39 +03:00
|
|
|
GridAreaShorthandStyleValue const& as_grid_area_shorthand() const;
|
2023-01-16 20:17:05 +03:00
|
|
|
GridTemplateAreaStyleValue const& as_grid_template_area() const;
|
2022-08-24 13:25:56 +03:00
|
|
|
GridTrackPlacementShorthandStyleValue const& as_grid_track_placement_shorthand() const;
|
2022-08-24 13:31:00 +03:00
|
|
|
GridTrackPlacementStyleValue const& as_grid_track_placement() const;
|
2023-04-29 20:32:56 +03:00
|
|
|
GridTrackSizeListShorthandStyleValue const& as_grid_track_size_list_shorthand() const;
|
2023-04-29 18:59:07 +03:00
|
|
|
GridTrackSizeListStyleValue const& as_grid_track_size_list() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
IdentifierStyleValue const& as_identifier() const;
|
|
|
|
ImageStyleValue const& as_image() const;
|
|
|
|
InheritStyleValue const& as_inherit() const;
|
|
|
|
InitialStyleValue const& as_initial() const;
|
|
|
|
LengthStyleValue const& as_length() const;
|
2022-07-12 02:09:29 +03:00
|
|
|
LinearGradientStyleValue const& as_linear_gradient() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
ListStyleStyleValue const& as_list_style() const;
|
|
|
|
NumericStyleValue const& as_numeric() const;
|
|
|
|
OverflowStyleValue const& as_overflow() const;
|
2022-01-14 20:09:02 +03:00
|
|
|
PercentageStyleValue const& as_percentage() const;
|
2021-10-31 19:02:29 +03:00
|
|
|
PositionStyleValue const& as_position() const;
|
2022-11-11 20:13:00 +03:00
|
|
|
RadialGradientStyleValue const& as_radial_gradient() const;
|
2022-07-31 19:46:35 +03:00
|
|
|
RectStyleValue const& as_rect() const;
|
2022-02-21 20:51:01 +03:00
|
|
|
ResolutionStyleValue const& as_resolution() const;
|
2022-03-23 19:55:22 +03:00
|
|
|
ShadowStyleValue const& as_shadow() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
StringStyleValue const& as_string() const;
|
|
|
|
TextDecorationStyleValue const& as_text_decoration() const;
|
2022-02-21 22:29:43 +03:00
|
|
|
TimeStyleValue const& as_time() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
TransformationStyleValue const& as_transformation() const;
|
2021-12-03 15:28:14 +03:00
|
|
|
UnresolvedStyleValue const& as_unresolved() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
UnsetStyleValue const& as_unset() const;
|
2023-04-20 20:31:00 +03:00
|
|
|
URLStyleValue const& as_url() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
StyleValueList const& as_value_list() const;
|
|
|
|
|
2022-07-31 03:11:59 +03:00
|
|
|
AbstractImageStyleValue& as_abstract_image() { return const_cast<AbstractImageStyleValue&>(const_cast<StyleValue const&>(*this).as_abstract_image()); }
|
2022-02-21 20:43:30 +03:00
|
|
|
AngleStyleValue& as_angle() { return const_cast<AngleStyleValue&>(const_cast<StyleValue const&>(*this).as_angle()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
BackgroundStyleValue& as_background() { return const_cast<BackgroundStyleValue&>(const_cast<StyleValue const&>(*this).as_background()); }
|
2021-10-31 19:02:29 +03:00
|
|
|
BackgroundRepeatStyleValue& as_background_repeat() { return const_cast<BackgroundRepeatStyleValue&>(const_cast<StyleValue const&>(*this).as_background_repeat()); }
|
2021-11-05 15:18:23 +03:00
|
|
|
BackgroundSizeStyleValue& as_background_size() { return const_cast<BackgroundSizeStyleValue&>(const_cast<StyleValue const&>(*this).as_background_size()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
BorderRadiusStyleValue& as_border_radius() { return const_cast<BorderRadiusStyleValue&>(const_cast<StyleValue const&>(*this).as_border_radius()); }
|
2022-04-18 19:04:38 +03:00
|
|
|
BorderRadiusShorthandStyleValue& as_border_radius_shorthand() { return const_cast<BorderRadiusShorthandStyleValue&>(const_cast<StyleValue const&>(*this).as_border_radius_shorthand()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
BorderStyleValue& as_border() { return const_cast<BorderStyleValue&>(const_cast<StyleValue const&>(*this).as_border()); }
|
|
|
|
CalculatedStyleValue& as_calculated() { return const_cast<CalculatedStyleValue&>(const_cast<StyleValue const&>(*this).as_calculated()); }
|
|
|
|
ColorStyleValue& as_color() { return const_cast<ColorStyleValue&>(const_cast<StyleValue const&>(*this).as_color()); }
|
2022-10-28 22:44:00 +03:00
|
|
|
ConicGradientStyleValue& as_conic_gradient() { return const_cast<ConicGradientStyleValue&>(const_cast<StyleValue const&>(*this).as_conic_gradient()); }
|
2022-02-23 22:56:25 +03:00
|
|
|
ContentStyleValue& as_content() { return const_cast<ContentStyleValue&>(const_cast<StyleValue const&>(*this).as_content()); }
|
2023-04-26 22:05:38 +03:00
|
|
|
DisplayStyleValue& as_display() { return const_cast<DisplayStyleValue&>(const_cast<StyleValue const&>(*this).as_display()); }
|
2023-04-03 00:56:45 +03:00
|
|
|
EdgeStyleValue& as_edge() { return const_cast<EdgeStyleValue&>(const_cast<StyleValue const&>(*this).as_edge()); }
|
2022-09-15 10:31:14 +03:00
|
|
|
FilterValueListStyleValue& as_filter_value_list() { return const_cast<FilterValueListStyleValue&>(const_cast<StyleValue const&>(*this).as_filter_value_list()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
FlexFlowStyleValue& as_flex_flow() { return const_cast<FlexFlowStyleValue&>(const_cast<StyleValue const&>(*this).as_flex_flow()); }
|
|
|
|
FlexStyleValue& as_flex() { return const_cast<FlexStyleValue&>(const_cast<StyleValue const&>(*this).as_flex()); }
|
|
|
|
FontStyleValue& as_font() { return const_cast<FontStyleValue&>(const_cast<StyleValue const&>(*this).as_font()); }
|
2022-02-21 20:49:47 +03:00
|
|
|
FrequencyStyleValue& as_frequency() { return const_cast<FrequencyStyleValue&>(const_cast<StyleValue const&>(*this).as_frequency()); }
|
2023-01-16 21:02:39 +03:00
|
|
|
GridAreaShorthandStyleValue& as_grid_area_shorthand() { return const_cast<GridAreaShorthandStyleValue&>(const_cast<StyleValue const&>(*this).as_grid_area_shorthand()); }
|
2023-01-16 20:17:05 +03:00
|
|
|
GridTemplateAreaStyleValue& as_grid_template_area() { return const_cast<GridTemplateAreaStyleValue&>(const_cast<StyleValue const&>(*this).as_grid_template_area()); }
|
2022-08-24 13:25:56 +03:00
|
|
|
GridTrackPlacementShorthandStyleValue& as_grid_track_placement_shorthand() { return const_cast<GridTrackPlacementShorthandStyleValue&>(const_cast<StyleValue const&>(*this).as_grid_track_placement_shorthand()); }
|
2022-08-24 13:31:00 +03:00
|
|
|
GridTrackPlacementStyleValue& as_grid_track_placement() { return const_cast<GridTrackPlacementStyleValue&>(const_cast<StyleValue const&>(*this).as_grid_track_placement()); }
|
2023-04-29 20:32:56 +03:00
|
|
|
GridTrackSizeListShorthandStyleValue& as_grid_track_size_list_shorthand() { return const_cast<GridTrackSizeListShorthandStyleValue&>(const_cast<StyleValue const&>(*this).as_grid_track_size_list_shorthand()); }
|
2023-04-29 18:59:07 +03:00
|
|
|
GridTrackSizeListStyleValue& as_grid_track_size_list() { return const_cast<GridTrackSizeListStyleValue&>(const_cast<StyleValue const&>(*this).as_grid_track_size_list()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
IdentifierStyleValue& as_identifier() { return const_cast<IdentifierStyleValue&>(const_cast<StyleValue const&>(*this).as_identifier()); }
|
|
|
|
ImageStyleValue& as_image() { return const_cast<ImageStyleValue&>(const_cast<StyleValue const&>(*this).as_image()); }
|
|
|
|
InheritStyleValue& as_inherit() { return const_cast<InheritStyleValue&>(const_cast<StyleValue const&>(*this).as_inherit()); }
|
|
|
|
InitialStyleValue& as_initial() { return const_cast<InitialStyleValue&>(const_cast<StyleValue const&>(*this).as_initial()); }
|
|
|
|
LengthStyleValue& as_length() { return const_cast<LengthStyleValue&>(const_cast<StyleValue const&>(*this).as_length()); }
|
2022-07-12 02:09:29 +03:00
|
|
|
LinearGradientStyleValue& as_linear_gradient() { return const_cast<LinearGradientStyleValue&>(const_cast<StyleValue const&>(*this).as_linear_gradient()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
ListStyleStyleValue& as_list_style() { return const_cast<ListStyleStyleValue&>(const_cast<StyleValue const&>(*this).as_list_style()); }
|
|
|
|
NumericStyleValue& as_numeric() { return const_cast<NumericStyleValue&>(const_cast<StyleValue const&>(*this).as_numeric()); }
|
|
|
|
OverflowStyleValue& as_overflow() { return const_cast<OverflowStyleValue&>(const_cast<StyleValue const&>(*this).as_overflow()); }
|
2022-01-14 20:09:02 +03:00
|
|
|
PercentageStyleValue& as_percentage() { return const_cast<PercentageStyleValue&>(const_cast<StyleValue const&>(*this).as_percentage()); }
|
2021-10-31 19:02:29 +03:00
|
|
|
PositionStyleValue& as_position() { return const_cast<PositionStyleValue&>(const_cast<StyleValue const&>(*this).as_position()); }
|
2022-11-11 20:13:00 +03:00
|
|
|
RadialGradientStyleValue& as_radial_gradient() { return const_cast<RadialGradientStyleValue&>(const_cast<StyleValue const&>(*this).as_radial_gradient()); }
|
2022-07-31 19:46:35 +03:00
|
|
|
RectStyleValue& as_rect() { return const_cast<RectStyleValue&>(const_cast<StyleValue const&>(*this).as_rect()); }
|
2022-02-21 20:51:01 +03:00
|
|
|
ResolutionStyleValue& as_resolution() { return const_cast<ResolutionStyleValue&>(const_cast<StyleValue const&>(*this).as_resolution()); }
|
2022-03-23 19:55:22 +03:00
|
|
|
ShadowStyleValue& as_shadow() { return const_cast<ShadowStyleValue&>(const_cast<StyleValue const&>(*this).as_shadow()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
StringStyleValue& as_string() { return const_cast<StringStyleValue&>(const_cast<StyleValue const&>(*this).as_string()); }
|
|
|
|
TextDecorationStyleValue& as_text_decoration() { return const_cast<TextDecorationStyleValue&>(const_cast<StyleValue const&>(*this).as_text_decoration()); }
|
2022-02-21 22:29:43 +03:00
|
|
|
TimeStyleValue& as_time() { return const_cast<TimeStyleValue&>(const_cast<StyleValue const&>(*this).as_time()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
TransformationStyleValue& as_transformation() { return const_cast<TransformationStyleValue&>(const_cast<StyleValue const&>(*this).as_transformation()); }
|
2021-12-03 15:28:14 +03:00
|
|
|
UnresolvedStyleValue& as_unresolved() { return const_cast<UnresolvedStyleValue&>(const_cast<StyleValue const&>(*this).as_unresolved()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
UnsetStyleValue& as_unset() { return const_cast<UnsetStyleValue&>(const_cast<StyleValue const&>(*this).as_unset()); }
|
2023-04-20 20:31:00 +03:00
|
|
|
URLStyleValue& as_url() { return const_cast<URLStyleValue&>(const_cast<StyleValue const&>(*this).as_url()); }
|
2021-09-23 21:54:19 +03:00
|
|
|
StyleValueList& as_value_list() { return const_cast<StyleValueList&>(const_cast<StyleValue const&>(*this).as_value_list()); }
|
|
|
|
|
2023-04-19 14:00:38 +03:00
|
|
|
bool has_auto() const;
|
2021-09-23 21:54:19 +03:00
|
|
|
virtual bool has_color() const { return false; }
|
|
|
|
virtual bool has_length() const { return false; }
|
2022-07-31 19:46:35 +03:00
|
|
|
virtual bool has_rect() const { return false; }
|
2021-09-23 21:54:19 +03:00
|
|
|
virtual bool has_number() const { return false; }
|
2021-10-19 18:43:56 +03:00
|
|
|
virtual bool has_integer() const { return false; }
|
2021-09-23 14:45:08 +03:00
|
|
|
|
2023-05-01 22:09:05 +03:00
|
|
|
virtual ErrorOr<ValueComparingNonnullRefPtr<StyleValue const>> absolutized(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const;
|
2022-02-26 03:35:25 +03:00
|
|
|
|
2023-04-19 20:31:00 +03:00
|
|
|
virtual Color to_color(Optional<Layout::NodeWithStyle const&>) const { return {}; }
|
2023-04-19 14:00:38 +03:00
|
|
|
ValueID to_identifier() const;
|
2022-02-18 17:48:01 +03:00
|
|
|
virtual Length to_length() const { VERIFY_NOT_REACHED(); }
|
2021-10-19 18:43:56 +03:00
|
|
|
virtual float to_number() const { return 0; }
|
|
|
|
virtual float to_integer() const { return 0; }
|
2023-01-06 21:02:26 +03:00
|
|
|
virtual ErrorOr<String> to_string() const = 0;
|
2019-08-18 09:09:56 +03:00
|
|
|
|
2023-05-24 16:28:09 +03:00
|
|
|
[[nodiscard]] int to_font_weight() const;
|
|
|
|
[[nodiscard]] int to_font_slope() const;
|
|
|
|
|
2023-02-20 03:41:51 +03:00
|
|
|
virtual bool equals(StyleValue const& other) const = 0;
|
|
|
|
|
|
|
|
bool operator==(StyleValue const& other) const
|
|
|
|
{
|
|
|
|
return this->equals(other);
|
|
|
|
}
|
2020-12-14 17:04:13 +03:00
|
|
|
|
2019-06-21 00:25:25 +03:00
|
|
|
protected:
|
|
|
|
explicit StyleValue(Type);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Type m_type { Type::Invalid };
|
|
|
|
};
|
2019-06-22 22:48:21 +03:00
|
|
|
|
2023-02-11 21:12:00 +03:00
|
|
|
template<typename T>
|
|
|
|
struct StyleValueWithDefaultOperators : public StyleValue {
|
|
|
|
using StyleValue::StyleValue;
|
|
|
|
|
2023-02-20 03:41:51 +03:00
|
|
|
virtual bool equals(StyleValue const& other) const override
|
2023-02-11 21:12:00 +03:00
|
|
|
{
|
|
|
|
if (type() != other.type())
|
|
|
|
return false;
|
|
|
|
auto const& typed_other = static_cast<T const&>(other);
|
2023-02-20 03:41:51 +03:00
|
|
|
return static_cast<T const&>(*this).properties_equal(typed_other);
|
2023-02-11 21:12:00 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-03-07 12:27:02 +03:00
|
|
|
}
|
2022-02-02 23:53:55 +03:00
|
|
|
|
|
|
|
template<>
|
|
|
|
struct AK::Formatter<Web::CSS::StyleValue> : Formatter<StringView> {
|
|
|
|
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::StyleValue const& style_value)
|
|
|
|
{
|
2023-01-06 21:02:26 +03:00
|
|
|
return Formatter<StringView>::format(builder, TRY(style_value.to_string()));
|
2022-02-02 23:53:55 +03:00
|
|
|
}
|
|
|
|
};
|