| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <AK/Optional.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-24 17:45:42 +02:00
										 |  |  | #include <LibWeb/CSS/LengthBox.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:34:40 +02:00
										 |  |  | #include <LibWeb/CSS/StyleValue.h>
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 10:34:31 +01:00
										 |  |  | namespace Web::CSS { | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 16:37:44 +02:00
										 |  |  | class InitialValues { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-06-26 15:08:42 +02:00
										 |  |  |     static CSS::Float float_() { return CSS::Float::None; } | 
					
						
							| 
									
										
										
										
											2020-12-06 01:45:51 +01:00
										 |  |  |     static CSS::Clear clear() { return CSS::Clear::None; } | 
					
						
							| 
									
										
										
										
											2021-02-21 17:41:00 +00:00
										 |  |  |     static CSS::Cursor cursor() { return CSS::Cursor::Auto; } | 
					
						
							| 
									
										
										
										
											2020-06-24 16:37:44 +02:00
										 |  |  |     static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; } | 
					
						
							| 
									
										
										
										
											2020-12-14 18:38:02 +01:00
										 |  |  |     static CSS::TextAlign text_align() { return CSS::TextAlign::Left; } | 
					
						
							| 
									
										
										
										
											2020-12-14 18:47:00 +01:00
										 |  |  |     static CSS::Position position() { return CSS::Position::Static; } | 
					
						
							| 
									
										
										
										
											2020-12-15 13:36:27 +01:00
										 |  |  |     static CSS::TextDecorationLine text_decoration_line() { return CSS::TextDecorationLine::None; } | 
					
						
							| 
									
										
										
										
											2020-12-15 14:15:49 +01:00
										 |  |  |     static CSS::TextTransform text_transform() { return CSS::TextTransform::None; } | 
					
						
							| 
									
										
										
										
											2021-01-07 14:41:50 +01:00
										 |  |  |     static CSS::Display display() { return CSS::Display::Inline; } | 
					
						
							| 
									
										
										
										
											2020-12-15 16:13:05 +01:00
										 |  |  |     static Color color() { return Color::Black; } | 
					
						
							|  |  |  |     static Color background_color() { return Color::Transparent; } | 
					
						
							| 
									
										
										
										
											2021-04-02 15:41:29 -04:00
										 |  |  |     static CSS::Repeat background_repeat() { return CSS::Repeat::Repeat; } | 
					
						
							| 
									
										
										
										
											2020-12-15 16:50:39 +01:00
										 |  |  |     static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; } | 
					
						
							| 
									
										
										
										
											2021-01-18 17:41:57 +01:00
										 |  |  |     static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; } | 
					
						
							| 
									
										
										
										
											2021-05-30 12:11:32 +02:00
										 |  |  |     static CSS::FlexWrap flex_wrap() { return CSS::FlexWrap::Nowrap; } | 
					
						
							| 
									
										
										
										
											2021-07-16 18:38:26 +02:00
										 |  |  |     static CSS::JustifyContent justify_content() { return CSS::JustifyContent::FlexStart; } | 
					
						
							| 
									
										
										
										
											2021-02-22 15:20:31 +01:00
										 |  |  |     static CSS::Overflow overflow() { return CSS::Overflow::Visible; } | 
					
						
							| 
									
										
										
										
											2020-06-24 16:37:44 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:12 +02:00
										 |  |  | struct BorderData { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     Color color { Color::Transparent }; | 
					
						
							| 
									
										
										
										
											2020-12-04 16:11:55 +01:00
										 |  |  |     CSS::LineStyle line_style { CSS::LineStyle::None }; | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:12 +02:00
										 |  |  |     float width { 0 }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-30 14:23:43 +02:00
										 |  |  | struct FlexBasisData { | 
					
						
							|  |  |  |     CSS::FlexBasis type { CSS::FlexBasis::Content }; | 
					
						
							|  |  |  |     CSS::Length length {}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 10:34:31 +01:00
										 |  |  | class ComputedValues { | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     CSS::Float float_() const { return m_noninherited.float_; } | 
					
						
							|  |  |  |     CSS::Clear clear() const { return m_noninherited.clear; } | 
					
						
							| 
									
										
										
										
											2021-02-21 17:41:00 +00:00
										 |  |  |     CSS::Cursor cursor() const { return m_inherited.cursor; } | 
					
						
							| 
									
										
										
										
											2021-01-07 14:41:50 +01:00
										 |  |  |     CSS::Display display() const { return m_noninherited.display; } | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     Optional<int> z_index() const { return m_noninherited.z_index; } | 
					
						
							|  |  |  |     CSS::TextAlign text_align() const { return m_inherited.text_align; } | 
					
						
							|  |  |  |     CSS::TextDecorationLine text_decoration_line() const { return m_noninherited.text_decoration_line; } | 
					
						
							|  |  |  |     CSS::TextTransform text_transform() const { return m_inherited.text_transform; } | 
					
						
							|  |  |  |     CSS::Position position() const { return m_noninherited.position; } | 
					
						
							|  |  |  |     CSS::WhiteSpace white_space() const { return m_inherited.white_space; } | 
					
						
							| 
									
										
										
										
											2021-01-18 17:41:57 +01:00
										 |  |  |     CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; } | 
					
						
							| 
									
										
										
										
											2021-05-30 12:11:32 +02:00
										 |  |  |     CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; } | 
					
						
							| 
									
										
										
										
											2021-05-30 14:23:43 +02:00
										 |  |  |     FlexBasisData flex_basis() const { return m_noninherited.flex_basis; } | 
					
						
							| 
									
										
										
										
											2021-05-30 20:22:25 +02:00
										 |  |  |     Optional<float> flex_grow_factor() const { return m_noninherited.flex_grow_factor; } | 
					
						
							|  |  |  |     Optional<float> flex_shrink_factor() const { return m_noninherited.flex_shrink_factor; } | 
					
						
							| 
									
										
										
										
											2021-07-16 18:38:26 +02:00
										 |  |  |     CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; } | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     const CSS::Length& width() const { return m_noninherited.width; } | 
					
						
							|  |  |  |     const CSS::Length& min_width() const { return m_noninherited.min_width; } | 
					
						
							|  |  |  |     const CSS::Length& max_width() const { return m_noninherited.max_width; } | 
					
						
							|  |  |  |     const CSS::Length& height() const { return m_noninherited.height; } | 
					
						
							|  |  |  |     const CSS::Length& min_height() const { return m_noninherited.min_height; } | 
					
						
							|  |  |  |     const CSS::Length& max_height() const { return m_noninherited.max_height; } | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     const CSS::LengthBox& offset() const { return m_noninherited.offset; } | 
					
						
							|  |  |  |     const CSS::LengthBox& margin() const { return m_noninherited.margin; } | 
					
						
							|  |  |  |     const CSS::LengthBox& padding() const { return m_noninherited.padding; } | 
					
						
							| 
									
										
										
										
											2020-06-24 17:45:42 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     const BorderData& border_left() const { return m_noninherited.border_left; } | 
					
						
							|  |  |  |     const BorderData& border_top() const { return m_noninherited.border_top; } | 
					
						
							|  |  |  |     const BorderData& border_right() const { return m_noninherited.border_right; } | 
					
						
							|  |  |  |     const BorderData& border_bottom() const { return m_noninherited.border_bottom; } | 
					
						
							| 
									
										
										
										
											2020-06-24 19:41:12 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-05-14 22:31:03 +02:00
										 |  |  |     const CSS::Length& border_bottom_left_radius() const { return m_noninherited.border_bottom_left_radius; } | 
					
						
							|  |  |  |     const CSS::Length& border_bottom_right_radius() const { return m_noninherited.border_bottom_right_radius; } | 
					
						
							|  |  |  |     const CSS::Length& border_top_left_radius() const { return m_noninherited.border_top_left_radius; } | 
					
						
							|  |  |  |     const CSS::Length& border_top_right_radius() const { return m_noninherited.border_top_right_radius; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-22 15:20:31 +01:00
										 |  |  |     CSS::Overflow overflow_x() const { return m_noninherited.overflow_x; } | 
					
						
							|  |  |  |     CSS::Overflow overflow_y() const { return m_noninherited.overflow_y; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     Color color() const { return m_inherited.color; } | 
					
						
							|  |  |  |     Color background_color() const { return m_noninherited.background_color; } | 
					
						
							| 
									
										
										
										
											2021-04-05 12:05:35 -04:00
										 |  |  |     CSS::Repeat background_repeat_x() const { return m_noninherited.background_repeat_x; } | 
					
						
							|  |  |  |     CSS::Repeat background_repeat_y() const { return m_noninherited.background_repeat_y; } | 
					
						
							| 
									
										
										
										
											2020-12-15 16:13:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     CSS::ListStyleType list_style_type() const { return m_inherited.list_style_type; } | 
					
						
							| 
									
										
										
										
											2020-12-15 16:50:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 14:10:53 +01:00
										 |  |  |     ComputedValues clone_inherited_values() const | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         ComputedValues clone; | 
					
						
							|  |  |  |         clone.m_inherited = m_inherited; | 
					
						
							|  |  |  |         return clone; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     struct { | 
					
						
							|  |  |  |         Color color { InitialValues::color() }; | 
					
						
							| 
									
										
										
										
											2021-02-21 17:41:00 +00:00
										 |  |  |         CSS::Cursor cursor { InitialValues::cursor() }; | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |         CSS::TextAlign text_align { InitialValues::text_align() }; | 
					
						
							|  |  |  |         CSS::TextTransform text_transform { InitialValues::text_transform() }; | 
					
						
							|  |  |  |         CSS::WhiteSpace white_space { InitialValues::white_space() }; | 
					
						
							|  |  |  |         CSS::ListStyleType list_style_type { InitialValues::list_style_type() }; | 
					
						
							|  |  |  |     } m_inherited; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     struct { | 
					
						
							|  |  |  |         CSS::Float float_ { InitialValues::float_() }; | 
					
						
							|  |  |  |         CSS::Clear clear { InitialValues::clear() }; | 
					
						
							| 
									
										
										
										
											2021-01-07 14:41:50 +01:00
										 |  |  |         CSS::Display display { InitialValues::display() }; | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |         Optional<int> z_index; | 
					
						
							|  |  |  |         CSS::TextDecorationLine text_decoration_line { InitialValues::text_decoration_line() }; | 
					
						
							|  |  |  |         CSS::Position position { InitialValues::position() }; | 
					
						
							|  |  |  |         CSS::Length width; | 
					
						
							|  |  |  |         CSS::Length min_width; | 
					
						
							|  |  |  |         CSS::Length max_width; | 
					
						
							|  |  |  |         CSS::Length height; | 
					
						
							|  |  |  |         CSS::Length min_height; | 
					
						
							|  |  |  |         CSS::Length max_height; | 
					
						
							|  |  |  |         CSS::LengthBox offset; | 
					
						
							|  |  |  |         CSS::LengthBox margin; | 
					
						
							|  |  |  |         CSS::LengthBox padding; | 
					
						
							|  |  |  |         BorderData border_left; | 
					
						
							|  |  |  |         BorderData border_top; | 
					
						
							|  |  |  |         BorderData border_right; | 
					
						
							|  |  |  |         BorderData border_bottom; | 
					
						
							| 
									
										
										
										
											2021-05-14 22:31:03 +02:00
										 |  |  |         Length border_bottom_left_radius; | 
					
						
							|  |  |  |         Length border_bottom_right_radius; | 
					
						
							|  |  |  |         Length border_top_left_radius; | 
					
						
							|  |  |  |         Length border_top_right_radius; | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |         Color background_color { InitialValues::background_color() }; | 
					
						
							| 
									
										
										
										
											2021-04-05 12:05:35 -04:00
										 |  |  |         CSS::Repeat background_repeat_x { InitialValues::background_repeat() }; | 
					
						
							|  |  |  |         CSS::Repeat background_repeat_y { InitialValues::background_repeat() }; | 
					
						
							| 
									
										
										
										
											2021-01-18 17:41:57 +01:00
										 |  |  |         CSS::FlexDirection flex_direction { InitialValues::flex_direction() }; | 
					
						
							| 
									
										
										
										
											2021-05-30 12:11:32 +02:00
										 |  |  |         CSS::FlexWrap flex_wrap { InitialValues::flex_wrap() }; | 
					
						
							| 
									
										
										
										
											2021-05-30 14:23:43 +02:00
										 |  |  |         CSS::FlexBasisData flex_basis {}; | 
					
						
							| 
									
										
										
										
											2021-05-30 20:22:25 +02:00
										 |  |  |         Optional<float> flex_grow_factor; | 
					
						
							|  |  |  |         Optional<float> flex_shrink_factor; | 
					
						
							| 
									
										
										
										
											2021-07-16 18:38:26 +02:00
										 |  |  |         CSS::JustifyContent justify_content { InitialValues::justify_content() }; | 
					
						
							| 
									
										
										
										
											2021-02-22 15:20:31 +01:00
										 |  |  |         CSS::Overflow overflow_x { InitialValues::overflow() }; | 
					
						
							|  |  |  |         CSS::Overflow overflow_y { InitialValues::overflow() }; | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     } m_noninherited; | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 10:34:31 +01:00
										 |  |  | class ImmutableComputedValues final : public ComputedValues { | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-06 10:34:31 +01:00
										 |  |  | class MutableComputedValues final : public ComputedValues { | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     void set_color(const Color& color) { m_inherited.color = color; } | 
					
						
							| 
									
										
										
										
											2021-02-21 17:41:00 +00:00
										 |  |  |     void set_cursor(CSS::Cursor cursor) { m_inherited.cursor = cursor; } | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     void set_background_color(const Color& color) { m_noninherited.background_color = color; } | 
					
						
							| 
									
										
										
										
											2021-04-05 12:05:35 -04:00
										 |  |  |     void set_background_repeat_x(CSS::Repeat repeat) { m_noninherited.background_repeat_x = repeat; } | 
					
						
							|  |  |  |     void set_background_repeat_y(CSS::Repeat repeat) { m_noninherited.background_repeat_y = repeat; } | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     void set_float(CSS::Float value) { m_noninherited.float_ = value; } | 
					
						
							|  |  |  |     void set_clear(CSS::Clear value) { m_noninherited.clear = value; } | 
					
						
							|  |  |  |     void set_z_index(Optional<int> value) { m_noninherited.z_index = value; } | 
					
						
							|  |  |  |     void set_text_align(CSS::TextAlign text_align) { m_inherited.text_align = text_align; } | 
					
						
							|  |  |  |     void set_text_decoration_line(CSS::TextDecorationLine value) { m_noninherited.text_decoration_line = value; } | 
					
						
							|  |  |  |     void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; } | 
					
						
							|  |  |  |     void set_position(CSS::Position position) { m_noninherited.position = position; } | 
					
						
							|  |  |  |     void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; } | 
					
						
							|  |  |  |     void set_width(const CSS::Length& width) { m_noninherited.width = width; } | 
					
						
							|  |  |  |     void set_min_width(const CSS::Length& width) { m_noninherited.min_width = width; } | 
					
						
							|  |  |  |     void set_max_width(const CSS::Length& width) { m_noninherited.max_width = width; } | 
					
						
							|  |  |  |     void set_height(const CSS::Length& height) { m_noninherited.height = height; } | 
					
						
							|  |  |  |     void set_min_height(const CSS::Length& height) { m_noninherited.min_height = height; } | 
					
						
							|  |  |  |     void set_max_height(const CSS::Length& height) { m_noninherited.max_height = height; } | 
					
						
							|  |  |  |     void set_offset(const CSS::LengthBox& offset) { m_noninherited.offset = offset; } | 
					
						
							|  |  |  |     void set_margin(const CSS::LengthBox& margin) { m_noninherited.margin = margin; } | 
					
						
							|  |  |  |     void set_padding(const CSS::LengthBox& padding) { m_noninherited.padding = padding; } | 
					
						
							| 
									
										
										
										
											2021-02-22 15:20:31 +01:00
										 |  |  |     void set_overflow_x(CSS::Overflow value) { m_noninherited.overflow_x = value; } | 
					
						
							|  |  |  |     void set_overflow_y(CSS::Overflow value) { m_noninherited.overflow_y = value; } | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     void set_list_style_type(CSS::ListStyleType value) { m_inherited.list_style_type = value; } | 
					
						
							| 
									
										
										
										
											2021-01-07 14:41:50 +01:00
										 |  |  |     void set_display(CSS::Display value) { m_noninherited.display = value; } | 
					
						
							| 
									
										
										
										
											2021-05-14 22:31:03 +02:00
										 |  |  |     void set_border_bottom_left_radius(CSS::Length value) { m_noninherited.border_bottom_left_radius = value; } | 
					
						
							|  |  |  |     void set_border_bottom_right_radius(CSS::Length value) { m_noninherited.border_bottom_right_radius = value; } | 
					
						
							|  |  |  |     void set_border_top_left_radius(CSS::Length value) { m_noninherited.border_top_left_radius = value; } | 
					
						
							|  |  |  |     void set_border_top_right_radius(CSS::Length value) { m_noninherited.border_top_right_radius = value; } | 
					
						
							| 
									
										
										
										
											2021-01-06 12:54:47 +01:00
										 |  |  |     BorderData& border_left() { return m_noninherited.border_left; } | 
					
						
							|  |  |  |     BorderData& border_top() { return m_noninherited.border_top; } | 
					
						
							|  |  |  |     BorderData& border_right() { return m_noninherited.border_right; } | 
					
						
							|  |  |  |     BorderData& border_bottom() { return m_noninherited.border_bottom; } | 
					
						
							| 
									
										
										
										
											2021-01-18 17:41:57 +01:00
										 |  |  |     void set_flex_direction(CSS::FlexDirection value) { m_noninherited.flex_direction = value; } | 
					
						
							| 
									
										
										
										
											2021-05-30 12:11:32 +02:00
										 |  |  |     void set_flex_wrap(CSS::FlexWrap value) { m_noninherited.flex_wrap = value; } | 
					
						
							| 
									
										
										
										
											2021-05-30 14:23:43 +02:00
										 |  |  |     void set_flex_basis(FlexBasisData value) { m_noninherited.flex_basis = value; } | 
					
						
							| 
									
										
										
										
											2021-05-30 20:22:25 +02:00
										 |  |  |     void set_flex_grow_factor(Optional<float> value) { m_noninherited.flex_grow_factor = value; } | 
					
						
							|  |  |  |     void set_flex_shrink_factor(Optional<float> value) { m_noninherited.flex_shrink_factor = value; } | 
					
						
							| 
									
										
										
										
											2021-07-16 18:38:26 +02:00
										 |  |  |     void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; } | 
					
						
							| 
									
										
										
										
											2020-06-24 14:17:05 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |