2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2023-05-24 15:28:09 +02:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.org>
|
2024-08-14 10:54:09 +01:00
|
|
|
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.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
|
|
|
*/
|
|
|
|
|
2023-05-24 15:28:09 +02:00
|
|
|
#include <LibGfx/Font/FontStyleMapping.h>
|
2024-01-16 14:53:44 +00:00
|
|
|
#include <LibGfx/Font/FontWeight.h>
|
2024-08-14 11:10:54 +01:00
|
|
|
#include <LibWeb/CSS/CSSStyleValue.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>
|
2024-05-25 23:06:47 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/BasicShapeStyleValue.h>
|
2023-03-25 00:33:20 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
2024-08-14 11:46:56 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.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>
|
2024-07-24 15:47:11 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
|
2024-07-24 14:56:16 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/CounterStyleValue.h>
|
2023-05-25 12:43:52 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
2023-04-26 21:05:38 +02:00
|
|
|
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
2023-07-06 02:29:36 +03:30
|
|
|
#include <LibWeb/CSS/StyleValues/EasingStyleValue.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-09-28 15:18:14 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
2023-03-23 21:50:24 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
2023-08-17 20:25:18 +02:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
|
2023-03-24 14:25:00 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
2023-03-24 14:53:08 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
2023-04-29 17:59:07 +02:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
|
2023-03-24 15:17:11 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
2023-06-01 17:01:09 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.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-09-07 15:29:54 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
|
2023-06-01 16:16:15 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/NumberStyleValue.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-06-06 15:42:43 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/RatioStyleValue.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>
|
2024-06-26 23:19:38 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h>
|
2023-03-24 17:45:25 +00:00
|
|
|
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
|
2023-09-19 12:21:15 +01:00
|
|
|
#include <LibWeb/CSS/StyleValues/ShorthandStyleValue.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 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>
|
2024-02-19 19:01:34 -07:00
|
|
|
#include <LibWeb/CSS/StyleValues/TransitionStyleValue.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>
|
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
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
CSSStyleValue::CSSStyleValue(Type type)
|
2019-06-22 21:48:21 +02:00
|
|
|
: m_type(type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
AbstractImageStyleValue const& CSSStyleValue::as_abstract_image() const
|
2022-07-31 01:11:59 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_abstract_image());
|
|
|
|
return static_cast<AbstractImageStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
AngleStyleValue const& CSSStyleValue::as_angle() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_angle());
|
|
|
|
return static_cast<AngleStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
BackgroundRepeatStyleValue const& CSSStyleValue::as_background_repeat() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_background_repeat());
|
|
|
|
return static_cast<BackgroundRepeatStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
BackgroundSizeStyleValue const& CSSStyleValue::as_background_size() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_background_size());
|
|
|
|
return static_cast<BackgroundSizeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
BasicShapeStyleValue const& CSSStyleValue::as_basic_shape() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_basic_shape());
|
|
|
|
return static_cast<BasicShapeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
BorderRadiusStyleValue const& CSSStyleValue::as_border_radius() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_border_radius());
|
|
|
|
return static_cast<BorderRadiusStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
CalculatedStyleValue const& CSSStyleValue::as_calculated() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_calculated());
|
|
|
|
return static_cast<CalculatedStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ColorStyleValue const& CSSStyleValue::as_color() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_color());
|
|
|
|
return static_cast<ColorStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ConicGradientStyleValue const& CSSStyleValue::as_conic_gradient() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_conic_gradient());
|
|
|
|
return static_cast<ConicGradientStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ContentStyleValue const& CSSStyleValue::as_content() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_content());
|
|
|
|
return static_cast<ContentStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
CounterStyleValue const& CSSStyleValue::as_counter() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_counter());
|
|
|
|
return static_cast<CounterStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
CounterDefinitionsStyleValue const& CSSStyleValue::as_counter_definitions() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_counter_definitions());
|
|
|
|
return static_cast<CounterDefinitionsStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
CustomIdentStyleValue const& CSSStyleValue::as_custom_ident() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_custom_ident());
|
|
|
|
return static_cast<CustomIdentStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
DisplayStyleValue const& CSSStyleValue::as_display() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_display());
|
|
|
|
return static_cast<DisplayStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
EasingStyleValue const& CSSStyleValue::as_easing() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_easing());
|
|
|
|
return static_cast<EasingStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
EdgeStyleValue const& CSSStyleValue::as_edge() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_edge());
|
|
|
|
return static_cast<EdgeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
FilterValueListStyleValue const& CSSStyleValue::as_filter_value_list() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_filter_value_list());
|
|
|
|
return static_cast<FilterValueListStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
FlexStyleValue const& CSSStyleValue::as_flex() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_flex());
|
|
|
|
return static_cast<FlexStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
FrequencyStyleValue const& CSSStyleValue::as_frequency() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_frequency());
|
|
|
|
return static_cast<FrequencyStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
GridAutoFlowStyleValue const& CSSStyleValue::as_grid_auto_flow() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_grid_auto_flow());
|
|
|
|
return static_cast<GridAutoFlowStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
GridTemplateAreaStyleValue const& CSSStyleValue::as_grid_template_area() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_grid_template_area());
|
|
|
|
return static_cast<GridTemplateAreaStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
GridTrackPlacementStyleValue const& CSSStyleValue::as_grid_track_placement() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_grid_track_placement());
|
|
|
|
return static_cast<GridTrackPlacementStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
GridTrackSizeListStyleValue const& CSSStyleValue::as_grid_track_size_list() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_grid_track_size_list());
|
|
|
|
return static_cast<GridTrackSizeListStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:46:56 +01:00
|
|
|
CSSKeywordValue const& CSSStyleValue::as_keyword() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
2024-08-14 11:46:56 +01:00
|
|
|
VERIFY(is_keyword());
|
|
|
|
return static_cast<CSSKeywordValue const&>(*this);
|
2024-08-14 10:54:09 +01:00
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ImageStyleValue const& CSSStyleValue::as_image() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_image());
|
|
|
|
return static_cast<ImageStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
IntegerStyleValue const& CSSStyleValue::as_integer() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_integer());
|
|
|
|
return static_cast<IntegerStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
LengthStyleValue const& CSSStyleValue::as_length() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_length());
|
|
|
|
return static_cast<LengthStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
LinearGradientStyleValue const& CSSStyleValue::as_linear_gradient() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_linear_gradient());
|
|
|
|
return static_cast<LinearGradientStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
MathDepthStyleValue const& CSSStyleValue::as_math_depth() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_math_depth());
|
|
|
|
return static_cast<MathDepthStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
NumberStyleValue const& CSSStyleValue::as_number() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_number());
|
|
|
|
return static_cast<NumberStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
PercentageStyleValue const& CSSStyleValue::as_percentage() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_percentage());
|
|
|
|
return static_cast<PercentageStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
PositionStyleValue const& CSSStyleValue::as_position() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_position());
|
|
|
|
return static_cast<PositionStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
RadialGradientStyleValue const& CSSStyleValue::as_radial_gradient() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_radial_gradient());
|
|
|
|
return static_cast<RadialGradientStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
RatioStyleValue const& CSSStyleValue::as_ratio() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_ratio());
|
|
|
|
return static_cast<RatioStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
RectStyleValue const& CSSStyleValue::as_rect() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_rect());
|
|
|
|
return static_cast<RectStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ResolutionStyleValue const& CSSStyleValue::as_resolution() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_resolution());
|
|
|
|
return static_cast<ResolutionStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ScrollbarGutterStyleValue const& CSSStyleValue::as_scrollbar_gutter() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_scrollbar_gutter());
|
|
|
|
return static_cast<ScrollbarGutterStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ShadowStyleValue const& CSSStyleValue::as_shadow() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_shadow());
|
|
|
|
return static_cast<ShadowStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ShorthandStyleValue const& CSSStyleValue::as_shorthand() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_shorthand());
|
|
|
|
return static_cast<ShorthandStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
StringStyleValue const& CSSStyleValue::as_string() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_string());
|
|
|
|
return static_cast<StringStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
TimeStyleValue const& CSSStyleValue::as_time() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_time());
|
|
|
|
return static_cast<TimeStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
TransformationStyleValue const& CSSStyleValue::as_transformation() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_transformation());
|
|
|
|
return static_cast<TransformationStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
TransitionStyleValue const& CSSStyleValue::as_transition() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_transition());
|
|
|
|
return static_cast<TransitionStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
UnresolvedStyleValue const& CSSStyleValue::as_unresolved() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_unresolved());
|
|
|
|
return static_cast<UnresolvedStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
URLStyleValue const& CSSStyleValue::as_url() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_url());
|
|
|
|
return static_cast<URLStyleValue const&>(*this);
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
StyleValueList const& CSSStyleValue::as_value_list() const
|
2024-08-14 10:54:09 +01:00
|
|
|
{
|
|
|
|
VERIFY(is_value_list());
|
|
|
|
return static_cast<StyleValueList const&>(*this);
|
|
|
|
}
|
2021-09-23 19:54:19 +01:00
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
ValueComparingNonnullRefPtr<CSSStyleValue const> CSSStyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const
|
2023-03-31 14:25:38 +01:00
|
|
|
{
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
bool CSSStyleValue::has_auto() const
|
2023-04-19 12:00:38 +01:00
|
|
|
{
|
2024-08-14 14:06:03 +01:00
|
|
|
return is_keyword() && as_keyword().keyword() == Keyword::Auto;
|
2023-04-19 12:00:38 +01:00
|
|
|
}
|
|
|
|
|
2024-08-14 14:06:03 +01:00
|
|
|
Keyword CSSStyleValue::to_keyword() const
|
2023-04-19 12:00:38 +01:00
|
|
|
{
|
2024-08-14 11:46:56 +01:00
|
|
|
if (is_keyword())
|
2024-08-14 14:06:03 +01:00
|
|
|
return as_keyword().keyword();
|
|
|
|
return Keyword::Invalid;
|
2023-04-19 12:00:38 +01:00
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
int CSSStyleValue::to_font_weight() const
|
2023-05-24 15:28:09 +02:00
|
|
|
{
|
2024-08-14 11:46:56 +01:00
|
|
|
if (is_keyword()) {
|
2024-08-14 14:06:03 +01:00
|
|
|
switch (as_keyword().keyword()) {
|
|
|
|
case Keyword::Normal:
|
2023-05-24 15:28:09 +02:00
|
|
|
return Gfx::FontWeight::Regular;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Bold:
|
2023-05-24 15:28:09 +02:00
|
|
|
return Gfx::FontWeight::Bold;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Lighter:
|
2023-05-24 15:28:09 +02:00
|
|
|
// FIXME: This should be relative to the parent.
|
|
|
|
return Gfx::FontWeight::Regular;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Bolder:
|
2023-05-24 15:28:09 +02:00
|
|
|
// FIXME: This should be relative to the parent.
|
|
|
|
return Gfx::FontWeight::Bold;
|
|
|
|
default:
|
|
|
|
return Gfx::FontWeight::Regular;
|
|
|
|
}
|
|
|
|
}
|
2023-06-01 17:01:09 +01:00
|
|
|
if (is_number()) {
|
|
|
|
return round_to<int>(as_number().number());
|
2023-05-24 15:28:09 +02:00
|
|
|
}
|
|
|
|
if (is_calculated()) {
|
|
|
|
auto maybe_weight = const_cast<CalculatedStyleValue&>(as_calculated()).resolve_integer();
|
|
|
|
if (maybe_weight.has_value())
|
|
|
|
return maybe_weight.value();
|
|
|
|
}
|
|
|
|
return Gfx::FontWeight::Regular;
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
int CSSStyleValue::to_font_slope() const
|
2023-05-24 15:28:09 +02:00
|
|
|
{
|
|
|
|
// FIXME: Implement oblique <angle>
|
2024-08-14 11:46:56 +01:00
|
|
|
if (is_keyword()) {
|
2024-08-14 14:06:03 +01:00
|
|
|
switch (as_keyword().keyword()) {
|
|
|
|
case Keyword::Italic: {
|
2023-05-24 15:28:09 +02:00
|
|
|
static int italic_slope = Gfx::name_to_slope("Italic"sv);
|
|
|
|
return italic_slope;
|
|
|
|
}
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Oblique:
|
2023-05-24 15:28:09 +02:00
|
|
|
static int oblique_slope = Gfx::name_to_slope("Oblique"sv);
|
|
|
|
return oblique_slope;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Normal:
|
2023-05-24 15:28:09 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static int normal_slope = Gfx::name_to_slope("Normal"sv);
|
|
|
|
return normal_slope;
|
|
|
|
}
|
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
int CSSStyleValue::to_font_stretch_width() const
|
2023-08-07 21:44:10 +02:00
|
|
|
{
|
|
|
|
int width = Gfx::FontWidth::Normal;
|
2024-08-14 11:46:56 +01:00
|
|
|
if (is_keyword()) {
|
2024-08-14 14:06:03 +01:00
|
|
|
switch (as_keyword().keyword()) {
|
|
|
|
case Keyword::UltraCondensed:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::UltraCondensed;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::ExtraCondensed:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::ExtraCondensed;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Condensed:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::Condensed;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::SemiCondensed:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::SemiCondensed;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Normal:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::Normal;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::SemiExpanded:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::SemiExpanded;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::Expanded:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::Expanded;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::ExtraExpanded:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::ExtraExpanded;
|
|
|
|
break;
|
2024-08-14 14:06:03 +01:00
|
|
|
case Keyword::UltraExpanded:
|
2023-08-07 21:44:10 +02:00
|
|
|
width = Gfx::FontWidth::UltraExpanded;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (is_percentage()) {
|
|
|
|
float percentage = as_percentage().percentage().value();
|
|
|
|
if (percentage <= 50) {
|
|
|
|
width = Gfx::FontWidth::UltraCondensed;
|
|
|
|
} else if (percentage <= 62.5f) {
|
|
|
|
width = Gfx::FontWidth::ExtraCondensed;
|
|
|
|
} else if (percentage <= 75.0f) {
|
|
|
|
width = Gfx::FontWidth::Condensed;
|
|
|
|
} else if (percentage <= 87.5f) {
|
|
|
|
width = Gfx::FontWidth::SemiCondensed;
|
|
|
|
} else if (percentage <= 100.0f) {
|
|
|
|
width = Gfx::FontWidth::Normal;
|
|
|
|
} else if (percentage <= 112.5f) {
|
|
|
|
width = Gfx::FontWidth::SemiExpanded;
|
|
|
|
} else if (percentage <= 125.0f) {
|
|
|
|
width = Gfx::FontWidth::Expanded;
|
|
|
|
} else if (percentage <= 150.0f) {
|
|
|
|
width = Gfx::FontWidth::ExtraExpanded;
|
|
|
|
} else {
|
|
|
|
width = Gfx::FontWidth::UltraExpanded;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
2020-03-07 10:27:02 +01:00
|
|
|
}
|