2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2023-02-20 18:56:08 +01:00
|
|
|
* Copyright (c) 2018-2023, Andreas Kling <kling@serenityos.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>
|
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>
|
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
|
|
|
|
2019-10-04 12:12:39 +02:00
|
|
|
class StyleProperties : public RefCounted<StyleProperties> {
|
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
|
|
|
|
2021-04-23 16:46:57 +02:00
|
|
|
static NonnullRefPtr<StyleProperties> create() { return adopt_ref(*new StyleProperties); }
|
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
|
|
|
|
{
|
2022-02-18 20:21:49 +01:00
|
|
|
for (size_t i = 0; i < m_property_values.size(); ++i) {
|
2023-05-26 23:25:25 +03:30
|
|
|
if (m_property_values[i].has_value())
|
|
|
|
callback((CSS::PropertyID)i, *m_property_values[i]->style);
|
2022-02-18 20:21:49 +01:00
|
|
|
}
|
2019-09-21 15:32:17 +03:00
|
|
|
}
|
|
|
|
|
2023-07-29 17:14:18 +02:00
|
|
|
struct StyleAndSourceDeclaration {
|
|
|
|
NonnullRefPtr<StyleValue const> style;
|
|
|
|
CSS::CSSStyleDeclaration const* declaration = nullptr;
|
|
|
|
};
|
|
|
|
using PropertyValues = Array<Optional<StyleAndSourceDeclaration>, to_underlying(CSS::last_property_id) + 1>;
|
|
|
|
|
2022-02-18 20:21:49 +01:00
|
|
|
auto& properties() { return m_property_values; }
|
|
|
|
auto const& properties() const { return m_property_values; }
|
2021-09-23 13:13:51 +02:00
|
|
|
|
2023-05-26 23:25:25 +03:30
|
|
|
void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue const> value, CSS::CSSStyleDeclaration const* source_declaration = nullptr);
|
2023-02-20 18:56:08 +01:00
|
|
|
NonnullRefPtr<StyleValue const> property(CSS::PropertyID) const;
|
|
|
|
RefPtr<StyleValue const> maybe_null_property(CSS::PropertyID) const;
|
2023-05-26 23:25:25 +03:30
|
|
|
CSS::CSSStyleDeclaration const* property_source_declaration(CSS::PropertyID) const;
|
2019-09-21 15:32:17 +03:00
|
|
|
|
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;
|
2023-06-16 02:35:03 +00:00
|
|
|
CSS::Length border_spacing_horizontal() const;
|
|
|
|
CSS::Length border_spacing_vertical() 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;
|
2023-09-18 15:41:17 +01:00
|
|
|
struct ContentDataAndQuoteNestingLevel {
|
|
|
|
CSS::ContentData content_data;
|
|
|
|
u32 final_quote_nesting_level { 0 };
|
|
|
|
};
|
|
|
|
ContentDataAndQuoteNestingLevel content(u32 initial_quote_nesting_level) const;
|
2021-02-21 17:41:00 +00:00
|
|
|
Optional<CSS::Cursor> cursor() const;
|
2020-06-24 16:37:44 +02:00
|
|
|
Optional<CSS::WhiteSpace> white_space() 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;
|
2022-09-15 08:31:19 +01:00
|
|
|
CSS::BackdropFilter backdrop_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;
|
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-01-16 19:02:39 +01:00
|
|
|
String grid_area() 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;
|
2019-09-21 15:32:17 +03:00
|
|
|
|
2024-01-06 18:05:21 +01:00
|
|
|
static Vector<CSS::Transformation> transformations_for_style_value(StyleValue 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;
|
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;
|
|
|
|
float stroke_opacity() const;
|
2023-06-11 16:43:46 +01:00
|
|
|
Optional<CSS::FillRule> fill_rule() const;
|
2023-04-19 18:51:00 +01:00
|
|
|
|
2023-12-09 23:42:02 +01:00
|
|
|
Gfx::Font const& first_available_computed_font() const { return m_font_list->first(); }
|
|
|
|
|
|
|
|
Gfx::FontCascadeList const& computed_font_list() const
|
2021-09-23 13:13:51 +02:00
|
|
|
{
|
2023-12-09 23:42:02 +01:00
|
|
|
VERIFY(m_font_list);
|
|
|
|
return *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
|
|
|
{
|
2023-12-09 23:42:02 +01:00
|
|
|
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;
|
|
|
|
[[nodiscard]] CSSPixels compute_line_height(Layout::Node const&) const;
|
|
|
|
|
|
|
|
[[nodiscard]] CSSPixels line_height() const { return *m_line_height; }
|
|
|
|
void set_line_height(Badge<StyleComputer> const&, CSSPixels line_height) { 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);
|
|
|
|
int math_depth() const { return m_math_depth; }
|
|
|
|
|
2023-09-12 11:34:26 +01:00
|
|
|
QuotesData quotes() 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
|
|
|
|
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
|
|
|
|
2023-07-29 17:14:18 +02:00
|
|
|
PropertyValues m_property_values;
|
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
|
|
|
|
2023-09-07 15:29:54 +01:00
|
|
|
int m_math_depth { InitialValues::math_depth() };
|
2023-12-09 23:42:02 +01:00
|
|
|
mutable RefPtr<Gfx::FontCascadeList> m_font_list;
|
2024-01-12 12:39:40 +01:00
|
|
|
|
|
|
|
Optional<CSSPixels> m_line_height;
|
2019-09-21 15:32:17 +03:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|