2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2025-02-26 14:16:36 -03:00
|
|
|
* Copyright (c) 2018-2025, Andreas Kling <andreas@ladybird.org>
|
2025-02-21 10:04:20 -03:00
|
|
|
* Copyright (c) 2021-2025, Sam Atkins <sam@ladybird.org>
|
2022-01-24 14:38:29 -03:00
|
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
2023-01-13 20:44:44 -03:00
|
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2025-02-02 11:55:26 -03:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2023-05-24 10:28:09 -03:00
|
|
|
#include <LibGfx/Font/FontStyleMapping.h>
|
2024-01-16 11:53:44 -03:00
|
|
|
#include <LibGfx/Font/FontWeight.h>
|
2025-08-13 10:46:21 -03:00
|
|
|
#include <LibWeb/CSS/CSSStyleValue.h>
|
2025-07-10 08:17:27 -03:00
|
|
|
#include <LibWeb/CSS/Parser/Parser.h>
|
2023-03-24 13:42:50 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
|
2025-07-30 09:14:53 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/AnchorSizeStyleValue.h>
|
2025-08-03 09:58:13 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/AnchorStyleValue.h>
|
2023-03-23 14:26:13 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
|
2023-03-23 14:54:05 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/BackgroundSizeStyleValue.h>
|
2024-05-25 19:06:47 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/BasicShapeStyleValue.h>
|
2025-06-10 12:58:54 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/BorderImageSliceStyleValue.h>
|
2023-03-24 21:33:20 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/BorderRadiusStyleValue.h>
|
2024-12-11 12:05:56 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/CalculatedStyleValue.h>
|
2025-01-01 22:59:09 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h>
|
2025-08-08 07:24:15 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
2023-03-24 13:09:41 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
2023-03-23 18:17:43 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
2024-07-24 11:47:11 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
|
2024-07-24 10:56:16 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/CounterStyleValue.h>
|
2025-02-21 10:04:20 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/CursorStyleValue.h>
|
2023-05-25 08:43:52 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
2023-04-26 16:05:38 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
2023-07-05 19:59:36 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/EasingStyleValue.h>
|
2023-04-02 18:56:45 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
2023-03-23 18:26:03 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
2025-02-26 14:16:36 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/FitContentStyleValue.h>
|
2023-09-28 11:18:14 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/FlexStyleValue.h>
|
2025-04-02 13:01:16 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/FontSourceStyleValue.h>
|
2025-05-02 09:55:58 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/FontStyleStyleValue.h>
|
2023-03-23 18:50:24 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/FrequencyStyleValue.h>
|
2023-08-17 15:25:18 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
|
2023-03-24 11:25:00 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
|
2023-03-24 11:53:08 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
|
2023-04-29 12:59:07 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
|
2025-03-12 12:29:12 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/GuaranteedInvalidStyleValue.h>
|
2023-03-24 12:17:11 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
|
2023-06-01 13:01:09 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
|
2025-08-08 06:28:41 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/KeywordStyleValue.h>
|
2023-03-24 14:04:04 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
|
2023-03-24 13:17:50 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/LinearGradientStyleValue.h>
|
2023-09-07 11:29:54 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
|
2023-06-01 12:16:15 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
|
2024-09-30 13:05:52 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h>
|
2025-03-12 16:24:59 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/PendingSubstitutionStyleValue.h>
|
2023-03-24 14:28:43 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
|
2023-03-24 14:35:31 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
|
2023-03-24 13:35:18 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
|
2023-06-06 11:42:43 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
|
2023-03-24 21:02:50 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
|
2025-07-18 15:36:09 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/RepeatStyleStyleValue.h>
|
2023-03-24 14:40:28 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
|
2025-05-26 18:36:12 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ScrollbarColorStyleValue.h>
|
2024-06-26 19:19:38 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h>
|
2023-03-24 14:45:25 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
|
2023-09-19 08:21:15 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/ShorthandStyleValue.h>
|
2023-03-24 14:48:42 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/StringStyleValue.h>
|
2025-08-08 06:11:51 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
2023-03-24 21:12:21 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/StyleValueList.h>
|
2025-09-13 04:27:52 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/TextUnderlinePositionStyleValue.h>
|
2023-03-24 20:47:56 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
2023-03-24 14:59:33 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
2024-02-19 23:01:34 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/TransitionStyleValue.h>
|
2023-04-20 14:31:00 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
2025-03-27 14:35:06 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/UnicodeRangeStyleValue.h>
|
2023-03-24 20:53:41 -03:00
|
|
|
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
2025-07-18 20:31:07 -03:00
|
|
|
#include <LibWeb/Layout/Node.h>
|
2019-06-22 16:48:21 -03:00
|
|
|
|
2020-07-26 15:01:35 -03:00
|
|
|
namespace Web::CSS {
|
2020-03-07 06:27:02 -03:00
|
|
|
|
2025-07-19 00:38:16 -03:00
|
|
|
ColorResolutionContext ColorResolutionContext::for_element(DOM::AbstractElement const& element)
|
|
|
|
|
{
|
|
|
|
|
auto color_scheme = element.computed_properties()->color_scheme(element.document().page().preferred_color_scheme(), element.document().supported_color_schemes());
|
|
|
|
|
|
|
|
|
|
CalculationResolutionContext calculation_resolution_context { .length_resolution_context = Length::ResolutionContext::for_element(element) };
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
.color_scheme = color_scheme,
|
|
|
|
|
.current_color = element.computed_properties()->color_or_fallback(PropertyID::Color, { color_scheme, CSS::InitialValues::color(), element.document(), calculation_resolution_context }, CSS::InitialValues::color()),
|
|
|
|
|
.document = element.document(),
|
|
|
|
|
.calculation_resolution_context = calculation_resolution_context
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-18 20:31:07 -03:00
|
|
|
ColorResolutionContext ColorResolutionContext::for_layout_node_with_style(Layout::NodeWithStyle const& layout_node)
|
|
|
|
|
{
|
|
|
|
|
return {
|
|
|
|
|
.color_scheme = layout_node.computed_values().color_scheme(),
|
|
|
|
|
.current_color = layout_node.computed_values().color(),
|
|
|
|
|
.document = layout_node.document(),
|
|
|
|
|
.calculation_resolution_context = { .length_resolution_context = Length::ResolutionContext::for_layout_node(layout_node) },
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-08 06:11:51 -03:00
|
|
|
StyleValue::StyleValue(Type type)
|
2019-06-22 16:48:21 -03:00
|
|
|
: m_type(type)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-08 06:11:51 -03:00
|
|
|
AbstractImageStyleValue const& StyleValue::as_abstract_image() const
|
2022-07-30 21:11:59 -03:00
|
|
|
{
|
|
|
|
|
VERIFY(is_abstract_image());
|
|
|
|
|
return static_cast<AbstractImageStyleValue const&>(*this);
|
2025-07-30 09:14:53 -03:00
|
|
|
}
|
|
|
|
|
|
2025-08-08 07:08:54 -03:00
|
|
|
DimensionStyleValue const& StyleValue::as_dimension() const
|
|
|
|
|
{
|
|
|
|
|
VERIFY(is_dimension());
|
|
|
|
|
return static_cast<DimensionStyleValue const&>(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-08 04:09:51 -03:00
|
|
|
#define __ENUMERATE_CSS_STYLE_VALUE_TYPE(title_case, snake_case, style_value_class_name) \
|
2025-08-08 06:11:51 -03:00
|
|
|
style_value_class_name const& StyleValue::as_##snake_case() const \
|
2025-08-08 04:09:51 -03:00
|
|
|
{ \
|
|
|
|
|
VERIFY(is_##snake_case()); \
|
|
|
|
|
return static_cast<style_value_class_name const&>(*this); \
|
|
|
|
|
}
|
|
|
|
|
ENUMERATE_CSS_STYLE_VALUE_TYPES
|
|
|
|
|
#undef __ENUMERATE_CSS_STYLE_VALUE_TYPE
|
2021-09-23 15:54:19 -03:00
|
|
|
|
2025-08-08 06:11:51 -03:00
|
|
|
ValueComparingNonnullRefPtr<StyleValue const> StyleValue::absolutized(CSSPixelRect const&, Length::FontMetrics const&, Length::FontMetrics const&) const
|
2023-03-31 10:25:38 -03:00
|
|
|
{
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-08 06:11:51 -03:00
|
|
|
bool StyleValue::has_auto() const
|
2023-04-19 08:00:38 -03:00
|
|
|
{
|
2024-08-14 10:06:03 -03:00
|
|
|
return is_keyword() && as_keyword().keyword() == Keyword::Auto;
|
2023-04-19 08:00:38 -03:00
|
|
|
}
|
|
|
|
|
|
2025-08-08 06:11:51 -03:00
|
|
|
Vector<Parser::ComponentValue> StyleValue::tokenize() const
|
2025-07-10 08:17:27 -03:00
|
|
|
{
|
|
|
|
|
// This is an inefficient way of producing ComponentValues, but it's guaranteed to work for types that round-trip.
|
|
|
|
|
// FIXME: Implement better versions in the subclasses.
|
|
|
|
|
return Parser::Parser::create(Parser::ParsingParams {}, to_string(SerializationMode::Normal)).parse_as_list_of_component_values();
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-13 10:46:21 -03:00
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#reify-as-a-cssstylevalue
|
|
|
|
|
GC::Ref<CSSStyleValue> StyleValue::reify(JS::Realm& realm, String const& associated_property) const
|
|
|
|
|
{
|
|
|
|
|
// 1. Return a new CSSStyleValue object representing value whose [[associatedProperty]] internal slot is set to property.
|
|
|
|
|
return CSSStyleValue::create(realm, associated_property, to_string(SerializationMode::Normal));
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-07 06:27:02 -03:00
|
|
|
}
|