2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2024-08-02 11:58:56 +02:00
|
|
|
* Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
|
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
|
|
|
*/
|
|
|
|
|
2019-09-21 15:32:17 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/NonnullRefPtr.h>
|
2022-04-09 09:28:38 +02:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2023-12-09 23:42:02 +01:00
|
|
|
#include <LibGfx/FontCascadeList.h>
|
2020-02-15 00:10:34 +01:00
|
|
|
#include <LibGfx/Forward.h>
|
2024-04-05 13:47:48 -07:00
|
|
|
#include <LibJS/Heap/GCPtr.h>
|
2021-05-30 14:23:43 +02:00
|
|
|
#include <LibWeb/CSS/ComputedValues.h>
|
2020-06-24 17:45:42 +02:00
|
|
|
#include <LibWeb/CSS/LengthBox.h>
|
2023-03-25 14:11:11 +00:00
|
|
|
#include <LibWeb/CSS/PropertyID.h>
|
2024-08-02 13:59:19 +02:00
|
|
|
#include <LibWeb/CSS/StyleProperty.h>
|
2019-09-21 15:32:17 +03:00
|
|
|
|
2020-07-26 20:01:35 +02:00
|
|
|
namespace Web::CSS {
|
2020-03-07 10:27:02 +01:00
|
|
|
|
2024-10-26 17:42:27 +02:00
|
|
|
class StyleProperties {
|
2024-09-10 11:46:32 +02:00
|
|
|
public:
|
|
|
|
static constexpr size_t number_of_properties = to_underlying(CSS::last_property_id) + 1;
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct Data : public RefCounted<Data> {
|
|
|
|
friend class StyleComputer;
|
|
|
|
|
|
|
|
NonnullRefPtr<Data> clone() const;
|
|
|
|
|
2024-09-19 14:14:13 +01:00
|
|
|
// FIXME: These need protection from GC!
|
2024-09-10 11:46:32 +02:00
|
|
|
JS::GCPtr<CSS::CSSStyleDeclaration const> m_animation_name_source;
|
2024-09-19 14:14:13 +01:00
|
|
|
JS::GCPtr<CSS::CSSStyleDeclaration const> m_transition_property_source;
|
2024-09-10 11:46:32 +02:00
|
|
|
|
|
|
|
Array<RefPtr<CSSStyleValue const>, number_of_properties> m_property_values;
|
|
|
|
Array<u8, ceil_div(number_of_properties, 8uz)> m_property_important {};
|
|
|
|
Array<u8, ceil_div(number_of_properties, 8uz)> m_property_inherited {};
|
|
|
|
|
|
|
|
HashMap<CSS::PropertyID, NonnullRefPtr<CSSStyleValue const>> m_animated_property_values;
|
|
|
|
|
|
|
|
int m_math_depth { InitialValues::math_depth() };
|
|
|
|
mutable RefPtr<Gfx::FontCascadeList> m_font_list;
|
|
|
|
|
|
|
|
Optional<CSSPixels> m_line_height;
|
|
|
|
};
|
|
|
|
|
2019-09-21 15:32:17 +03:00
|
|
|
public:
|
2022-03-14 13:21:51 -06:00
|
|
|
StyleProperties() = default;
|
2020-01-05 16:54:38 +01:00
|
|
|
|
2019-09-21 15:32:17 +03:00
|
|
|
template<typename Callback>
|
|
|
|
inline void for_each_property(Callback callback) const
|
|
|
|
{
|
2024-09-10 11:46:32 +02:00
|
|
|
for (size_t i = 0; i < m_data->m_property_values.size(); ++i) {
|
|
|
|
if (m_data->m_property_values[i])
|
|
|
|
callback((CSS::PropertyID)i, *m_data->m_property_values[i]);
|
2022-02-18 20:21:49 +01:00
|
|
|
}
|
2019-09-21 15:32:17 +03:00
|
|
|
}
|
|
|
|
|
2024-03-16 07:44:48 +01:00
|
|
|
enum class Inherited {
|
|
|
|
No,
|
|
|
|
Yes
|
|
|
|
};
|
|
|
|
|
2024-09-10 11:46:32 +02:00
|
|
|
HashMap<CSS::PropertyID, NonnullRefPtr<CSSStyleValue const>> const& animated_property_values() const { return m_data->m_animated_property_values; }
|
2024-03-16 07:44:48 +01:00
|
|
|
void reset_animated_properties();
|
|
|
|
|
|
|
|
bool is_property_important(CSS::PropertyID property_id) const;
|
|
|
|
bool is_property_inherited(CSS::PropertyID property_id) const;
|
2024-08-02 13:59:19 +02:00
|
|
|
void set_property_important(CSS::PropertyID, Important);
|
|
|
|
void set_property_inherited(CSS::PropertyID, Inherited);
|
2024-03-16 07:44:48 +01:00
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
void set_property(CSS::PropertyID, NonnullRefPtr<CSSStyleValue const> value, Inherited = Inherited::No, Important = Important::No);
|
|
|
|
void set_animated_property(CSS::PropertyID, NonnullRefPtr<CSSStyleValue const> value);
|
2024-09-19 10:46:32 +01:00
|
|
|
enum class WithAnimationsApplied {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
NonnullRefPtr<CSSStyleValue const> property(CSS::PropertyID, WithAnimationsApplied = WithAnimationsApplied::Yes) const;
|
2024-08-14 11:10:54 +01:00
|
|
|
RefPtr<CSSStyleValue const> maybe_null_property(CSS::PropertyID) const;
|
2024-08-04 10:08:28 +02:00
|
|
|
void revert_property(CSS::PropertyID, StyleProperties const& style_for_revert);
|
2024-08-02 11:58:56 +02:00
|
|
|
|
2024-09-10 11:46:32 +02:00
|
|
|
JS::GCPtr<CSS::CSSStyleDeclaration const> animation_name_source() const { return m_data->m_animation_name_source; }
|
|
|
|
void set_animation_name_source(JS::GCPtr<CSS::CSSStyleDeclaration const> declaration) { m_data->m_animation_name_source = declaration; }
|
2019-09-21 15:32:17 +03:00
|
|
|
|
2024-09-19 14:14:13 +01:00
|
|
|
JS::GCPtr<CSS::CSSStyleDeclaration const> transition_property_source() const { return m_data->m_transition_property_source; }
|
|
|
|
void set_transition_property_source(JS::GCPtr<CSS::CSSStyleDeclaration const> declaration) { m_data->m_transition_property_source = declaration; }
|
|
|
|
|
2022-09-25 15:47:40 +02:00
|
|
|
CSS::Size size_value(CSS::PropertyID) const;
|
2022-01-19 16:19:43 +00:00
|
|
|
LengthPercentage length_percentage_or_fallback(CSS::PropertyID, LengthPercentage const& fallback) const;
|
2022-02-18 15:10:11 +00:00
|
|
|
Optional<LengthPercentage> length_percentage(CSS::PropertyID) const;
|
2020-12-15 20:01:00 +01:00
|
|
|
LengthBox length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const;
|
2021-09-16 19:20:20 +01:00
|
|
|
Color color_or_fallback(CSS::PropertyID, Layout::NodeWithStyle const&, Color fallback) const;
|
2023-07-19 19:12:00 +01:00
|
|
|
Optional<CSS::TextAnchor> text_anchor() const;
|
2020-12-14 18:38:02 +01:00
|
|
|
Optional<CSS::TextAlign> text_align() const;
|
2022-03-12 19:31:32 +00:00
|
|
|
Optional<CSS::TextJustify> text_justify() const;
|
2024-07-24 20:58:17 +02:00
|
|
|
Optional<CSS::TextOverflow> text_overflow() const;
|
2024-10-09 13:36:09 +02:00
|
|
|
CSS::Length border_spacing_horizontal(Layout::Node const&) const;
|
|
|
|
CSS::Length border_spacing_vertical(Layout::Node const&) const;
|
2023-06-07 02:10:55 +00:00
|
|
|
Optional<CSS::CaptionSide> caption_side() const;
|
2022-07-31 18:47:09 +02:00
|
|
|
CSS::Clip clip() const;
|
2020-06-24 16:22:16 +02:00
|
|
|
CSS::Display display() const;
|
2020-06-26 15:08:42 +02:00
|
|
|
Optional<CSS::Float> float_() const;
|
2020-12-06 01:45:51 +01:00
|
|
|
Optional<CSS::Clear> clear() const;
|
2024-08-20 20:23:55 -04:00
|
|
|
Optional<CSS::ColumnSpan> column_span() const;
|
2023-09-18 15:41:17 +01:00
|
|
|
struct ContentDataAndQuoteNestingLevel {
|
|
|
|
CSS::ContentData content_data;
|
|
|
|
u32 final_quote_nesting_level { 0 };
|
|
|
|
};
|
2024-07-18 20:29:02 +01:00
|
|
|
ContentDataAndQuoteNestingLevel content(DOM::Element&, u32 initial_quote_nesting_level) const;
|
2024-06-23 14:52:56 +02:00
|
|
|
Optional<CSS::ContentVisibility> content_visibility() const;
|
2021-02-21 17:41:00 +00:00
|
|
|
Optional<CSS::Cursor> cursor() const;
|
2024-10-01 13:07:06 +01:00
|
|
|
Variant<LengthOrCalculated, NumberOrCalculated> tab_size() const;
|
2020-06-24 16:37:44 +02:00
|
|
|
Optional<CSS::WhiteSpace> white_space() const;
|
2024-10-25 16:47:05 +01:00
|
|
|
Optional<CSS::WordBreak> word_break() const;
|
2024-10-18 21:00:28 +01:00
|
|
|
Optional<CSS::LengthOrCalculated> word_spacing() const;
|
2024-10-22 14:21:20 +01:00
|
|
|
Optional<LengthOrCalculated> letter_spacing() const;
|
2020-12-04 16:11:55 +01:00
|
|
|
Optional<CSS::LineStyle> line_style(CSS::PropertyID) const;
|
2023-08-02 17:24:14 +01:00
|
|
|
Optional<CSS::OutlineStyle> outline_style() const;
|
2022-04-14 16:22:35 +01:00
|
|
|
Vector<CSS::TextDecorationLine> text_decoration_line() const;
|
2022-01-20 20:27:55 +01:00
|
|
|
Optional<CSS::TextDecorationStyle> text_decoration_style() const;
|
2020-12-15 14:15:49 +01:00
|
|
|
Optional<CSS::TextTransform> text_transform() const;
|
2023-05-31 16:07:06 -04:00
|
|
|
Vector<CSS::ShadowData> text_shadow(Layout::Node const&) const;
|
2020-12-15 16:50:39 +01:00
|
|
|
Optional<CSS::ListStyleType> list_style_type() const;
|
2023-06-02 23:05:15 +02:00
|
|
|
Optional<CSS::ListStylePosition> list_style_position() const;
|
2021-01-18 17:41:57 +01:00
|
|
|
Optional<CSS::FlexDirection> flex_direction() const;
|
2021-05-30 12:11:32 +02:00
|
|
|
Optional<CSS::FlexWrap> flex_wrap() const;
|
2023-06-21 19:39:07 +02:00
|
|
|
Optional<CSS::FlexBasis> flex_basis() const;
|
2021-10-19 15:22:08 +02:00
|
|
|
float flex_grow() const;
|
|
|
|
float flex_shrink() const;
|
2022-03-31 22:11:38 +02:00
|
|
|
int order() const;
|
2023-03-18 20:49:00 +01:00
|
|
|
Optional<Color> accent_color(Layout::NodeWithStyle const&) const;
|
2022-10-14 13:50:06 +02:00
|
|
|
Optional<CSS::AlignContent> align_content() const;
|
2021-09-15 18:27:20 +02:00
|
|
|
Optional<CSS::AlignItems> align_items() const;
|
2022-07-11 23:52:36 +02:00
|
|
|
Optional<CSS::AlignSelf> align_self() const;
|
2022-07-22 16:05:11 +01:00
|
|
|
Optional<CSS::Appearance> appearance() const;
|
2024-10-25 11:00:22 +02:00
|
|
|
CSS::Filter backdrop_filter() const;
|
|
|
|
CSS::Filter filter() const;
|
2021-10-19 15:27:40 +02:00
|
|
|
float opacity() const;
|
2022-03-21 15:42:57 +01:00
|
|
|
Optional<CSS::Visibility> visibility() const;
|
2022-02-18 12:21:27 +01:00
|
|
|
Optional<CSS::ImageRendering> image_rendering() const;
|
2021-07-16 18:38:26 +02:00
|
|
|
Optional<CSS::JustifyContent> justify_content() const;
|
2023-07-14 20:49:22 +02:00
|
|
|
Optional<CSS::JustifyItems> justify_items() const;
|
2023-07-14 14:41:22 +02:00
|
|
|
Optional<CSS::JustifySelf> justify_self() const;
|
2021-02-22 15:20:31 +01:00
|
|
|
Optional<CSS::Overflow> overflow_x() const;
|
|
|
|
Optional<CSS::Overflow> overflow_y() const;
|
2023-05-31 16:07:06 -04:00
|
|
|
Vector<CSS::ShadowData> box_shadow(Layout::Node const&) const;
|
2022-04-13 19:33:56 +01:00
|
|
|
Optional<CSS::BoxSizing> box_sizing() const;
|
2021-10-05 19:47:13 +01:00
|
|
|
Optional<CSS::PointerEvents> pointer_events() const;
|
2022-02-26 01:34:07 +01:00
|
|
|
Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align() const;
|
2022-03-23 14:54:21 +01:00
|
|
|
Optional<CSS::FontVariant> font_variant() const;
|
2024-09-27 17:11:05 +01:00
|
|
|
Optional<FlyString> font_language_override() const;
|
2024-10-01 09:37:43 +01:00
|
|
|
Optional<HashMap<FlyString, IntegerOrCalculated>> font_feature_settings() const;
|
2024-10-01 09:20:06 +01:00
|
|
|
Optional<HashMap<FlyString, NumberOrCalculated>> font_variation_settings() const;
|
2023-05-21 18:08:41 +03:00
|
|
|
CSS::GridTrackSizeList grid_auto_columns() const;
|
|
|
|
CSS::GridTrackSizeList grid_auto_rows() const;
|
2022-10-30 13:27:57 +01:00
|
|
|
CSS::GridTrackSizeList grid_template_columns() const;
|
|
|
|
CSS::GridTrackSizeList grid_template_rows() const;
|
2023-08-17 20:25:18 +02:00
|
|
|
[[nodiscard]] CSS::GridAutoFlow grid_auto_flow() const;
|
2022-08-23 19:58:00 +02:00
|
|
|
CSS::GridTrackPlacement grid_column_end() const;
|
|
|
|
CSS::GridTrackPlacement grid_column_start() const;
|
|
|
|
CSS::GridTrackPlacement grid_row_end() const;
|
|
|
|
CSS::GridTrackPlacement grid_row_start() const;
|
2023-01-02 23:01:29 +01:00
|
|
|
Optional<CSS::BorderCollapse> border_collapse() const;
|
2023-01-16 18:17:05 +01:00
|
|
|
Vector<Vector<String>> grid_template_areas() const;
|
2023-08-01 20:06:50 +02:00
|
|
|
Optional<CSS::ObjectFit> object_fit() const;
|
2024-02-26 11:33:54 +01:00
|
|
|
CSS::ObjectPosition object_position() const;
|
2023-08-07 01:32:52 +00:00
|
|
|
Optional<CSS::TableLayout> table_layout() const;
|
2024-08-10 23:13:26 +01:00
|
|
|
Optional<CSS::Direction> direction() const;
|
2024-10-03 21:09:29 +02:00
|
|
|
Optional<CSS::UnicodeBidi> unicode_bidi() const;
|
2024-10-27 22:12:54 +00:00
|
|
|
Optional<CSS::WritingMode> writing_mode() const;
|
2019-09-21 15:32:17 +03:00
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
static Vector<CSS::Transformation> transformations_for_style_value(CSSStyleValue const& value);
|
2021-09-18 17:20:00 +02:00
|
|
|
Vector<CSS::Transformation> transformations() const;
|
2024-01-25 17:02:37 +00:00
|
|
|
Optional<CSS::TransformBox> transform_box() const;
|
2022-03-21 19:38:00 +01:00
|
|
|
CSS::TransformOrigin transform_origin() const;
|
2024-10-16 08:50:35 +02:00
|
|
|
Optional<CSS::Transformation> rotate(Layout::Node const&) const;
|
2021-09-18 17:20:00 +02:00
|
|
|
|
2023-10-08 11:06:34 +01:00
|
|
|
Optional<CSS::MaskType> mask_type() const;
|
2023-04-19 18:51:00 +01:00
|
|
|
Color stop_color() const;
|
2023-05-19 20:35:39 +01:00
|
|
|
float stop_opacity() const;
|
|
|
|
float fill_opacity() const;
|
2024-10-10 10:15:49 -04:00
|
|
|
Optional<CSS::StrokeLinecap> stroke_linecap() const;
|
2024-10-28 20:51:16 -04:00
|
|
|
Optional<CSS::StrokeLinejoin> stroke_linejoin() const;
|
|
|
|
NumberOrCalculated stroke_miterlimit() const;
|
2023-05-19 20:35:39 +01:00
|
|
|
float stroke_opacity() const;
|
2023-06-11 16:43:46 +01:00
|
|
|
Optional<CSS::FillRule> fill_rule() const;
|
2024-05-12 20:19:43 +01:00
|
|
|
Optional<CSS::ClipRule> clip_rule() const;
|
2023-04-19 18:51:00 +01:00
|
|
|
|
2024-09-10 11:46:32 +02:00
|
|
|
Gfx::Font const& first_available_computed_font() const { return m_data->m_font_list->first(); }
|
2023-12-09 23:42:02 +01:00
|
|
|
|
|
|
|
Gfx::FontCascadeList const& computed_font_list() const
|
2021-09-23 13:13:51 +02:00
|
|
|
{
|
2024-09-10 11:46:32 +02:00
|
|
|
VERIFY(m_data->m_font_list);
|
|
|
|
return *m_data->m_font_list;
|
2021-09-23 13:13:51 +02:00
|
|
|
}
|
|
|
|
|
2023-12-09 23:42:02 +01:00
|
|
|
void set_computed_font_list(NonnullRefPtr<Gfx::FontCascadeList> font_list) const
|
2021-09-23 13:13:51 +02:00
|
|
|
{
|
2024-09-10 11:46:32 +02:00
|
|
|
m_data->m_font_list = move(font_list);
|
2021-09-23 13:13:51 +02:00
|
|
|
}
|
|
|
|
|
2024-01-12 12:39:40 +01:00
|
|
|
[[nodiscard]] CSSPixels compute_line_height(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const;
|
|
|
|
|
2024-09-10 11:46:32 +02:00
|
|
|
[[nodiscard]] CSSPixels line_height() const { return *m_data->m_line_height; }
|
|
|
|
void set_line_height(Badge<StyleComputer> const&, CSSPixels line_height) { m_data->m_line_height = line_height; }
|
2019-10-12 13:42:58 +02:00
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
bool operator==(StyleProperties const&) const;
|
2019-10-14 18:32:02 +02:00
|
|
|
|
2023-10-27 15:17:36 +02:00
|
|
|
Optional<CSS::Positioning> position() const;
|
2020-06-15 17:29:35 +02:00
|
|
|
Optional<int> z_index() const;
|
2020-03-23 17:29:15 +01:00
|
|
|
|
2023-09-07 15:29:54 +01:00
|
|
|
void set_math_depth(int math_depth);
|
2024-09-10 11:46:32 +02:00
|
|
|
int math_depth() const { return m_data->m_math_depth; }
|
2023-09-07 15:29:54 +01:00
|
|
|
|
2023-09-12 11:34:26 +01:00
|
|
|
QuotesData quotes() const;
|
2024-07-24 15:47:11 +01:00
|
|
|
Vector<CounterData> counter_data(PropertyID) const;
|
2023-09-12 11:34:26 +01:00
|
|
|
|
2024-02-27 09:37:18 +01:00
|
|
|
Optional<CSS::ScrollbarWidth> scrollbar_width() const;
|
|
|
|
|
2023-02-20 18:56:08 +01:00
|
|
|
static NonnullRefPtr<Gfx::Font const> font_fallback(bool monospace, bool bold);
|
2021-09-23 13:13:51 +02:00
|
|
|
|
2024-08-14 11:10:54 +01:00
|
|
|
static float resolve_opacity_value(CSSStyleValue const& value);
|
2024-03-19 12:02:06 +01:00
|
|
|
|
2019-09-21 15:32:17 +03:00
|
|
|
private:
|
2021-09-24 13:49:57 +02:00
|
|
|
friend class StyleComputer;
|
2021-09-21 11:38:18 +02:00
|
|
|
|
2021-02-22 15:20:31 +01:00
|
|
|
Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
|
2023-05-31 16:07:06 -04:00
|
|
|
Vector<CSS::ShadowData> shadow(CSS::PropertyID, Layout::Node const&) const;
|
2019-10-06 11:23:58 +02:00
|
|
|
|
2024-09-10 11:46:32 +02:00
|
|
|
AK::CopyOnWrite<StyleProperties::Data> m_data;
|
2019-09-21 15:32:17 +03:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|