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>
|
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
|
|
|
|
2022-04-01 20:58:27 +03:00
|
|
|
explicit StyleProperties(StyleProperties const&);
|
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
|
|
|
|
|
|
|
NonnullRefPtr<StyleProperties> clone() const;
|
2019-10-04 12:12:39 +02: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) {
|
|
|
|
if (m_property_values[i])
|
|
|
|
callback((CSS::PropertyID)i, *m_property_values[i]);
|
|
|
|
}
|
2019-09-21 15:32:17 +03:00
|
|
|
}
|
|
|
|
|
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-02-20 18:56:08 +01:00
|
|
|
void set_property(CSS::PropertyID, NonnullRefPtr<StyleValue const> value);
|
|
|
|
NonnullRefPtr<StyleValue const> property(CSS::PropertyID) const;
|
|
|
|
RefPtr<StyleValue const> maybe_null_property(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;
|
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;
|
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;
|
2022-02-24 16:52:58 +00:00
|
|
|
CSS::ContentData content() 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;
|
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;
|
2022-03-23 21:16:36 +00:00
|
|
|
Vector<CSS::ShadowData> text_shadow() const;
|
2020-12-15 16:50:39 +01:00
|
|
|
Optional<CSS::ListStyleType> list_style_type() 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;
|
2021-05-30 14:23:43 +02:00
|
|
|
Optional<CSS::FlexBasisData> 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;
|
2021-02-22 15:20:31 +01:00
|
|
|
Optional<CSS::Overflow> overflow_x() const;
|
|
|
|
Optional<CSS::Overflow> overflow_y() const;
|
2022-03-23 16:55:22 +00:00
|
|
|
Vector<CSS::ShadowData> box_shadow() 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;
|
2022-10-30 13:27:57 +01:00
|
|
|
CSS::GridTrackSizeList grid_template_columns() const;
|
|
|
|
CSS::GridTrackSizeList grid_template_rows() 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;
|
2019-09-21 15:32:17 +03:00
|
|
|
|
2021-09-18 17:20:00 +02:00
|
|
|
Vector<CSS::Transformation> transformations() const;
|
2022-03-21 19:38:00 +01:00
|
|
|
CSS::TransformOrigin transform_origin() const;
|
2021-09-18 17:20:00 +02:00
|
|
|
|
2021-09-23 13:13:51 +02:00
|
|
|
Gfx::Font const& computed_font() const
|
|
|
|
{
|
|
|
|
VERIFY(m_font);
|
|
|
|
return *m_font;
|
|
|
|
}
|
|
|
|
|
2023-02-20 18:56:08 +01:00
|
|
|
void set_computed_font(NonnullRefPtr<Gfx::Font const> font)
|
2021-09-23 13:13:51 +02:00
|
|
|
{
|
|
|
|
m_font = move(font);
|
|
|
|
}
|
|
|
|
|
2023-03-17 23:08:45 +01:00
|
|
|
CSSPixels line_height(CSSPixelRect const& viewport_rect, Gfx::FontPixelMetrics const&, CSSPixels font_size, CSSPixels root_font_size, CSSPixels line_height, CSSPixels root_line_height) const;
|
2022-11-08 11:31:24 +00:00
|
|
|
CSSPixels line_height(Layout::Node const&) const;
|
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
|
|
|
|
2020-12-14 18:47:00 +01:00
|
|
|
Optional<CSS::Position> position() const;
|
2020-06-15 17:29:35 +02:00
|
|
|
Optional<int> z_index() const;
|
2020-03-23 17:29:15 +01:00
|
|
|
|
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-02-20 18:56:08 +01:00
|
|
|
Array<RefPtr<StyleValue const>, to_underlying(CSS::last_property_id) + 1> m_property_values;
|
2021-02-22 15:20:31 +01:00
|
|
|
Optional<CSS::Overflow> overflow(CSS::PropertyID) const;
|
2022-03-23 21:16:36 +00:00
|
|
|
Vector<CSS::ShadowData> shadow(CSS::PropertyID) const;
|
2019-10-06 11:23:58 +02:00
|
|
|
|
2023-02-20 18:56:08 +01:00
|
|
|
mutable RefPtr<Gfx::Font const> m_font;
|
2019-09-21 15:32:17 +03:00
|
|
|
};
|
2020-03-07 10:27:02 +01:00
|
|
|
|
|
|
|
}
|