ComputedValues.h 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. /*
  2. * Copyright (c) 2020-2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/Optional.h>
  8. #include <LibGfx/Painter.h>
  9. #include <LibWeb/CSS/BackdropFilter.h>
  10. #include <LibWeb/CSS/CalculatedOr.h>
  11. #include <LibWeb/CSS/Clip.h>
  12. #include <LibWeb/CSS/ColumnCount.h>
  13. #include <LibWeb/CSS/Display.h>
  14. #include <LibWeb/CSS/GridTrackPlacement.h>
  15. #include <LibWeb/CSS/GridTrackSize.h>
  16. #include <LibWeb/CSS/LengthBox.h>
  17. #include <LibWeb/CSS/PercentageOr.h>
  18. #include <LibWeb/CSS/Ratio.h>
  19. #include <LibWeb/CSS/Size.h>
  20. #include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
  21. #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
  22. #include <LibWeb/CSS/TransformFunctions.h>
  23. namespace Web::CSS {
  24. struct FlexBasisContent { };
  25. using FlexBasis = Variant<FlexBasisContent, Size>;
  26. struct AspectRatio {
  27. bool use_natural_aspect_ratio_if_available;
  28. Optional<Ratio> preferred_ratio;
  29. };
  30. struct GridAutoFlow {
  31. bool row { true };
  32. bool dense { false };
  33. };
  34. struct QuotesData {
  35. enum class Type {
  36. None,
  37. Auto,
  38. Specified,
  39. } type;
  40. Vector<Array<String, 2>> strings {};
  41. };
  42. class InitialValues {
  43. public:
  44. static AspectRatio aspect_ratio() { return AspectRatio { true, {} }; }
  45. static CSSPixels font_size() { return 16; }
  46. static int font_weight() { return 400; }
  47. static CSS::FontVariant font_variant() { return CSS::FontVariant::Normal; }
  48. static CSS::Float float_() { return CSS::Float::None; }
  49. static CSS::Length border_spacing() { return CSS::Length::make_px(0); }
  50. static CSS::CaptionSide caption_side() { return CSS::CaptionSide::Top; }
  51. static CSS::Clear clear() { return CSS::Clear::None; }
  52. static CSS::Clip clip() { return CSS::Clip::make_auto(); }
  53. static CSS::Cursor cursor() { return CSS::Cursor::Auto; }
  54. static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
  55. static CSS::TextAlign text_align() { return CSS::TextAlign::Left; }
  56. static CSS::TextJustify text_justify() { return CSS::TextJustify::Auto; }
  57. static CSS::Position position() { return CSS::Position::Static; }
  58. static CSS::TextDecorationLine text_decoration_line() { return CSS::TextDecorationLine::None; }
  59. static CSS::Length text_decoration_thickness() { return Length::make_auto(); }
  60. static CSS::TextDecorationStyle text_decoration_style() { return CSS::TextDecorationStyle::Solid; }
  61. static CSS::TextTransform text_transform() { return CSS::TextTransform::None; }
  62. static CSS::LengthPercentage text_indent() { return CSS::Length::make_px(0); }
  63. static CSS::Display display() { return CSS::Display { CSS::DisplayOutside::Inline, CSS::DisplayInside::Flow }; }
  64. static Color color() { return Color::Black; }
  65. static Color stop_color() { return Color::Black; }
  66. static CSS::BackdropFilter backdrop_filter() { return BackdropFilter::make_none(); }
  67. static Color background_color() { return Color::Transparent; }
  68. static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; }
  69. static CSS::ListStylePosition list_style_position() { return CSS::ListStylePosition::Outside; }
  70. static CSS::Visibility visibility() { return CSS::Visibility::Visible; }
  71. static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; }
  72. static CSS::FlexWrap flex_wrap() { return CSS::FlexWrap::Nowrap; }
  73. static CSS::FlexBasis flex_basis() { return CSS::Size::make_auto(); }
  74. static CSS::ImageRendering image_rendering() { return CSS::ImageRendering::Auto; }
  75. static CSS::JustifyContent justify_content() { return CSS::JustifyContent::FlexStart; }
  76. static CSS::JustifyItems justify_items() { return CSS::JustifyItems::Legacy; }
  77. static CSS::JustifySelf justify_self() { return CSS::JustifySelf::Auto; }
  78. static CSS::AlignContent align_content() { return CSS::AlignContent::Stretch; }
  79. static CSS::AlignItems align_items() { return CSS::AlignItems::Stretch; }
  80. static CSS::AlignSelf align_self() { return CSS::AlignSelf::Auto; }
  81. static CSS::Appearance appearance() { return CSS::Appearance::Auto; }
  82. static CSS::Overflow overflow() { return CSS::Overflow::Visible; }
  83. static CSS::BoxSizing box_sizing() { return CSS::BoxSizing::ContentBox; }
  84. static CSS::PointerEvents pointer_events() { return CSS::PointerEvents::Auto; }
  85. static float flex_grow() { return 0.0f; }
  86. static float flex_shrink() { return 1.0f; }
  87. static int order() { return 0; }
  88. static float opacity() { return 1.0f; }
  89. static float fill_opacity() { return 1.0f; }
  90. static CSS::FillRule fill_rule() { return CSS::FillRule::Nonzero; }
  91. static float stroke_opacity() { return 1.0f; }
  92. static float stop_opacity() { return 1.0f; }
  93. static CSS::TextAnchor text_anchor() { return CSS::TextAnchor::Start; }
  94. static CSS::Length border_radius() { return Length::make_px(0); }
  95. static Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align() { return CSS::VerticalAlign::Baseline; }
  96. static CSS::LengthBox inset() { return { CSS::Length::make_auto(), CSS::Length::make_auto(), CSS::Length::make_auto(), CSS::Length::make_auto() }; }
  97. static CSS::LengthBox margin() { return { CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0) }; }
  98. static CSS::LengthBox padding() { return { CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0), CSS::Length::make_px(0) }; }
  99. static CSS::Size width() { return CSS::Size::make_auto(); }
  100. static CSS::Size min_width() { return CSS::Size::make_auto(); }
  101. static CSS::Size max_width() { return CSS::Size::make_none(); }
  102. static CSS::Size height() { return CSS::Size::make_auto(); }
  103. static CSS::Size min_height() { return CSS::Size::make_auto(); }
  104. static CSS::Size max_height() { return CSS::Size::make_none(); }
  105. static CSS::GridTrackSizeList grid_template_columns() { return CSS::GridTrackSizeList::make_none(); }
  106. static CSS::GridTrackSizeList grid_template_rows() { return CSS::GridTrackSizeList::make_none(); }
  107. static CSS::GridTrackPlacement grid_column_end() { return CSS::GridTrackPlacement::make_auto(); }
  108. static CSS::GridTrackPlacement grid_column_start() { return CSS::GridTrackPlacement::make_auto(); }
  109. static CSS::GridTrackPlacement grid_row_end() { return CSS::GridTrackPlacement::make_auto(); }
  110. static CSS::GridTrackPlacement grid_row_start() { return CSS::GridTrackPlacement::make_auto(); }
  111. static CSS::GridAutoFlow grid_auto_flow() { return CSS::GridAutoFlow {}; }
  112. static ColumnCount column_count() { return ColumnCount::make_auto(); }
  113. static CSS::Size column_gap() { return CSS::Size::make_auto(); }
  114. static CSS::Size row_gap() { return CSS::Size::make_auto(); }
  115. static CSS::BorderCollapse border_collapse() { return CSS::BorderCollapse::Separate; }
  116. static Vector<Vector<String>> grid_template_areas() { return {}; }
  117. static CSS::Time transition_delay() { return CSS::Time::make_seconds(0); }
  118. static CSS::ObjectFit object_fit() { return CSS::ObjectFit::Fill; }
  119. static Color outline_color() { return Color::Black; }
  120. static CSS::Length outline_offset() { return CSS::Length::make_px(0); }
  121. static CSS::OutlineStyle outline_style() { return CSS::OutlineStyle::None; }
  122. static CSS::Length outline_width() { return CSS::Length::make_px(3); }
  123. static CSS::TableLayout table_layout() { return CSS::TableLayout::Auto; }
  124. static QuotesData quotes() { return QuotesData { .type = QuotesData::Type::Auto }; }
  125. static CSS::MathShift math_shift() { return CSS::MathShift::Normal; }
  126. static CSS::MathStyle math_style() { return CSS::MathStyle::Normal; }
  127. static int math_depth() { return 0; }
  128. };
  129. enum class BackgroundSize {
  130. Contain,
  131. Cover,
  132. LengthPercentage,
  133. };
  134. // https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
  135. class SVGPaint {
  136. public:
  137. SVGPaint(Color color)
  138. : m_value(color)
  139. {
  140. }
  141. SVGPaint(AK::URL const& url)
  142. : m_value(url)
  143. {
  144. }
  145. bool is_color() const { return m_value.has<Color>(); }
  146. bool is_url() const { return m_value.has<AK::URL>(); }
  147. Color as_color() const { return m_value.get<Color>(); }
  148. AK::URL const& as_url() const { return m_value.get<AK::URL>(); }
  149. private:
  150. Variant<AK::URL, Color> m_value;
  151. };
  152. // https://drafts.fxtf.org/css-masking-1/#typedef-mask-reference
  153. class MaskReference {
  154. public:
  155. // TODO: Support other mask types.
  156. MaskReference(AK::URL const& url)
  157. : m_url(url)
  158. {
  159. }
  160. AK::URL const& url() const { return m_url; }
  161. private:
  162. AK::URL m_url;
  163. };
  164. struct BackgroundLayerData {
  165. RefPtr<CSS::AbstractImageStyleValue const> background_image { nullptr };
  166. CSS::BackgroundAttachment attachment { CSS::BackgroundAttachment::Scroll };
  167. CSS::BackgroundBox origin { CSS::BackgroundBox::PaddingBox };
  168. CSS::BackgroundBox clip { CSS::BackgroundBox::BorderBox };
  169. CSS::PositionEdge position_edge_x { CSS::PositionEdge::Left };
  170. CSS::LengthPercentage position_offset_x { CSS::Length::make_px(0) };
  171. CSS::PositionEdge position_edge_y { CSS::PositionEdge::Top };
  172. CSS::LengthPercentage position_offset_y { CSS::Length::make_px(0) };
  173. CSS::BackgroundSize size_type { CSS::BackgroundSize::LengthPercentage };
  174. CSS::LengthPercentage size_x { CSS::Length::make_auto() };
  175. CSS::LengthPercentage size_y { CSS::Length::make_auto() };
  176. CSS::Repeat repeat_x { CSS::Repeat::Repeat };
  177. CSS::Repeat repeat_y { CSS::Repeat::Repeat };
  178. };
  179. struct BorderData {
  180. public:
  181. Color color { Color::Transparent };
  182. CSS::LineStyle line_style { CSS::LineStyle::None };
  183. CSSPixels width { 0 };
  184. bool operator==(BorderData const&) const = default;
  185. };
  186. using TransformValue = Variant<CSS::AngleOrCalculated, CSS::LengthPercentage, double>;
  187. struct Transformation {
  188. CSS::TransformFunction function;
  189. Vector<TransformValue> values;
  190. };
  191. struct TransformOrigin {
  192. CSS::LengthPercentage x { Percentage(50) };
  193. CSS::LengthPercentage y { Percentage(50) };
  194. };
  195. struct ShadowData {
  196. Color color {};
  197. CSS::Length offset_x { Length::make_px(0) };
  198. CSS::Length offset_y { Length::make_px(0) };
  199. CSS::Length blur_radius { Length::make_px(0) };
  200. CSS::Length spread_distance { Length::make_px(0) };
  201. CSS::ShadowPlacement placement { CSS::ShadowPlacement::Outer };
  202. };
  203. struct ContentData {
  204. enum class Type {
  205. Normal,
  206. None,
  207. String,
  208. } type { Type::Normal };
  209. // FIXME: Data is a list of identifiers, strings and image values.
  210. String data {};
  211. String alt_text {};
  212. };
  213. struct BorderRadiusData {
  214. CSS::LengthPercentage horizontal_radius { InitialValues::border_radius() };
  215. CSS::LengthPercentage vertical_radius { InitialValues::border_radius() };
  216. };
  217. // FIXME: Find a better place for this helper.
  218. inline Gfx::Painter::ScalingMode to_gfx_scaling_mode(CSS::ImageRendering css_value, Gfx::IntRect source, Gfx::IntRect target)
  219. {
  220. switch (css_value) {
  221. case CSS::ImageRendering::Auto:
  222. case CSS::ImageRendering::HighQuality:
  223. case CSS::ImageRendering::Smooth:
  224. if (target.width() < source.width() || target.height() < source.height())
  225. return Gfx::Painter::ScalingMode::BoxSampling;
  226. return Gfx::Painter::ScalingMode::BilinearBlend;
  227. case CSS::ImageRendering::CrispEdges:
  228. return Gfx::Painter::ScalingMode::NearestNeighbor;
  229. case CSS::ImageRendering::Pixelated:
  230. return Gfx::Painter::ScalingMode::SmoothPixels;
  231. }
  232. VERIFY_NOT_REACHED();
  233. }
  234. class ComputedValues {
  235. public:
  236. AspectRatio aspect_ratio() const { return m_noninherited.aspect_ratio; }
  237. CSS::Float float_() const { return m_noninherited.float_; }
  238. CSS::Length border_spacing_horizontal() const { return m_inherited.border_spacing_horizontal; }
  239. CSS::Length border_spacing_vertical() const { return m_inherited.border_spacing_vertical; }
  240. CSS::CaptionSide caption_side() const { return m_inherited.caption_side; }
  241. CSS::Clear clear() const { return m_noninherited.clear; }
  242. CSS::Clip clip() const { return m_noninherited.clip; }
  243. CSS::Cursor cursor() const { return m_inherited.cursor; }
  244. CSS::ContentData content() const { return m_noninherited.content; }
  245. CSS::PointerEvents pointer_events() const { return m_inherited.pointer_events; }
  246. CSS::Display display() const { return m_noninherited.display; }
  247. Optional<int> const& z_index() const { return m_noninherited.z_index; }
  248. CSS::TextAlign text_align() const { return m_inherited.text_align; }
  249. CSS::TextJustify text_justify() const { return m_inherited.text_justify; }
  250. CSS::LengthPercentage const& text_indent() const { return m_inherited.text_indent; }
  251. Vector<CSS::TextDecorationLine> const& text_decoration_line() const { return m_noninherited.text_decoration_line; }
  252. CSS::LengthPercentage const& text_decoration_thickness() const { return m_noninherited.text_decoration_thickness; }
  253. CSS::TextDecorationStyle text_decoration_style() const { return m_noninherited.text_decoration_style; }
  254. Color text_decoration_color() const { return m_noninherited.text_decoration_color; }
  255. CSS::TextTransform text_transform() const { return m_inherited.text_transform; }
  256. Vector<ShadowData> const& text_shadow() const { return m_inherited.text_shadow; }
  257. CSS::Position position() const { return m_noninherited.position; }
  258. CSS::WhiteSpace white_space() const { return m_inherited.white_space; }
  259. CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; }
  260. CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; }
  261. FlexBasis const& flex_basis() const { return m_noninherited.flex_basis; }
  262. float flex_grow() const { return m_noninherited.flex_grow; }
  263. float flex_shrink() const { return m_noninherited.flex_shrink; }
  264. int order() const { return m_noninherited.order; }
  265. Optional<Color> accent_color() const { return m_inherited.accent_color; }
  266. CSS::AlignContent align_content() const { return m_noninherited.align_content; }
  267. CSS::AlignItems align_items() const { return m_noninherited.align_items; }
  268. CSS::AlignSelf align_self() const { return m_noninherited.align_self; }
  269. CSS::Appearance appearance() const { return m_noninherited.appearance; }
  270. float opacity() const { return m_noninherited.opacity; }
  271. CSS::Visibility visibility() const { return m_inherited.visibility; }
  272. CSS::ImageRendering image_rendering() const { return m_inherited.image_rendering; }
  273. CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
  274. CSS::JustifySelf justify_self() const { return m_noninherited.justify_self; }
  275. CSS::JustifyItems justify_items() const { return m_noninherited.justify_items; }
  276. CSS::BackdropFilter const& backdrop_filter() const { return m_noninherited.backdrop_filter; }
  277. Vector<ShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
  278. CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
  279. CSS::Size const& width() const { return m_noninherited.width; }
  280. CSS::Size const& min_width() const { return m_noninherited.min_width; }
  281. CSS::Size const& max_width() const { return m_noninherited.max_width; }
  282. CSS::Size const& height() const { return m_noninherited.height; }
  283. CSS::Size const& min_height() const { return m_noninherited.min_height; }
  284. CSS::Size const& max_height() const { return m_noninherited.max_height; }
  285. Variant<CSS::VerticalAlign, CSS::LengthPercentage> const& vertical_align() const { return m_noninherited.vertical_align; }
  286. CSS::GridTrackSizeList const& grid_auto_columns() const { return m_noninherited.grid_auto_columns; }
  287. CSS::GridTrackSizeList const& grid_auto_rows() const { return m_noninherited.grid_auto_rows; }
  288. CSS::GridAutoFlow const& grid_auto_flow() const { return m_noninherited.grid_auto_flow; }
  289. CSS::GridTrackSizeList const& grid_template_columns() const { return m_noninherited.grid_template_columns; }
  290. CSS::GridTrackSizeList const& grid_template_rows() const { return m_noninherited.grid_template_rows; }
  291. CSS::GridTrackPlacement const& grid_column_end() const { return m_noninherited.grid_column_end; }
  292. CSS::GridTrackPlacement const& grid_column_start() const { return m_noninherited.grid_column_start; }
  293. CSS::GridTrackPlacement const& grid_row_end() const { return m_noninherited.grid_row_end; }
  294. CSS::GridTrackPlacement const& grid_row_start() const { return m_noninherited.grid_row_start; }
  295. CSS::ColumnCount column_count() const { return m_noninherited.column_count; }
  296. CSS::Size const& column_gap() const { return m_noninherited.column_gap; }
  297. CSS::Size const& row_gap() const { return m_noninherited.row_gap; }
  298. CSS::BorderCollapse border_collapse() const { return m_inherited.border_collapse; }
  299. Vector<Vector<String>> const& grid_template_areas() const { return m_noninherited.grid_template_areas; }
  300. CSS::LengthBox const& inset() const { return m_noninherited.inset; }
  301. const CSS::LengthBox& margin() const { return m_noninherited.margin; }
  302. const CSS::LengthBox& padding() const { return m_noninherited.padding; }
  303. BorderData const& border_left() const { return m_noninherited.border_left; }
  304. BorderData const& border_top() const { return m_noninherited.border_top; }
  305. BorderData const& border_right() const { return m_noninherited.border_right; }
  306. BorderData const& border_bottom() const { return m_noninherited.border_bottom; }
  307. const CSS::BorderRadiusData& border_bottom_left_radius() const { return m_noninherited.border_bottom_left_radius; }
  308. const CSS::BorderRadiusData& border_bottom_right_radius() const { return m_noninherited.border_bottom_right_radius; }
  309. const CSS::BorderRadiusData& border_top_left_radius() const { return m_noninherited.border_top_left_radius; }
  310. const CSS::BorderRadiusData& border_top_right_radius() const { return m_noninherited.border_top_right_radius; }
  311. CSS::Overflow overflow_x() const { return m_noninherited.overflow_x; }
  312. CSS::Overflow overflow_y() const { return m_noninherited.overflow_y; }
  313. Color color() const { return m_inherited.color; }
  314. Color background_color() const { return m_noninherited.background_color; }
  315. Vector<BackgroundLayerData> const& background_layers() const { return m_noninherited.background_layers; }
  316. CSS::ListStyleType list_style_type() const { return m_inherited.list_style_type; }
  317. CSS::ListStylePosition list_style_position() const { return m_inherited.list_style_position; }
  318. Optional<SVGPaint> const& fill() const { return m_inherited.fill; }
  319. CSS::FillRule fill_rule() const { return m_inherited.fill_rule; }
  320. Optional<SVGPaint> const& stroke() const { return m_inherited.stroke; }
  321. float fill_opacity() const { return m_inherited.fill_opacity; }
  322. float stroke_opacity() const { return m_inherited.stroke_opacity; }
  323. LengthPercentage const& stroke_width() const { return m_inherited.stroke_width; }
  324. Color stop_color() const { return m_noninherited.stop_color; }
  325. float stop_opacity() const { return m_noninherited.stop_opacity; }
  326. CSS::TextAnchor text_anchor() const { return m_inherited.text_anchor; }
  327. Optional<MaskReference> const& mask() const { return m_noninherited.mask; }
  328. Vector<CSS::Transformation> const& transformations() const { return m_noninherited.transformations; }
  329. CSS::TransformOrigin const& transform_origin() const { return m_noninherited.transform_origin; }
  330. CSSPixels font_size() const { return m_inherited.font_size; }
  331. int font_weight() const { return m_inherited.font_weight; }
  332. CSS::FontVariant font_variant() const { return m_inherited.font_variant; }
  333. CSS::Time transition_delay() const { return m_noninherited.transition_delay; }
  334. Color outline_color() const { return m_noninherited.outline_color; }
  335. CSS::Length outline_offset() const { return m_noninherited.outline_offset; }
  336. CSS::OutlineStyle outline_style() const { return m_noninherited.outline_style; }
  337. CSS::Length outline_width() const { return m_noninherited.outline_width; }
  338. CSS::TableLayout table_layout() const { return m_noninherited.table_layout; }
  339. CSS::QuotesData quotes() const { return m_inherited.quotes; }
  340. CSS::MathShift math_shift() const { return m_inherited.math_shift; }
  341. CSS::MathStyle math_style() const { return m_inherited.math_style; }
  342. int math_depth() const { return m_inherited.math_depth; }
  343. ComputedValues clone_inherited_values() const
  344. {
  345. ComputedValues clone;
  346. clone.m_inherited = m_inherited;
  347. return clone;
  348. }
  349. protected:
  350. struct {
  351. CSSPixels font_size { InitialValues::font_size() };
  352. int font_weight { InitialValues::font_weight() };
  353. CSS::FontVariant font_variant { InitialValues::font_variant() };
  354. CSS::BorderCollapse border_collapse { InitialValues::border_collapse() };
  355. CSS::Length border_spacing_horizontal { InitialValues::border_spacing() };
  356. CSS::Length border_spacing_vertical { InitialValues::border_spacing() };
  357. CSS::CaptionSide caption_side { InitialValues::caption_side() };
  358. Color color { InitialValues::color() };
  359. Optional<Color> accent_color {};
  360. CSS::Cursor cursor { InitialValues::cursor() };
  361. CSS::ImageRendering image_rendering { InitialValues::image_rendering() };
  362. CSS::PointerEvents pointer_events { InitialValues::pointer_events() };
  363. CSS::TextAlign text_align { InitialValues::text_align() };
  364. CSS::TextJustify text_justify { InitialValues::text_justify() };
  365. CSS::TextTransform text_transform { InitialValues::text_transform() };
  366. CSS::LengthPercentage text_indent { InitialValues::text_indent() };
  367. CSS::WhiteSpace white_space { InitialValues::white_space() };
  368. CSS::ListStyleType list_style_type { InitialValues::list_style_type() };
  369. CSS::ListStylePosition list_style_position { InitialValues::list_style_position() };
  370. CSS::Visibility visibility { InitialValues::visibility() };
  371. CSS::QuotesData quotes { InitialValues::quotes() };
  372. Optional<SVGPaint> fill;
  373. CSS::FillRule fill_rule { InitialValues::fill_rule() };
  374. Optional<SVGPaint> stroke;
  375. float fill_opacity { InitialValues::fill_opacity() };
  376. float stroke_opacity { InitialValues::stroke_opacity() };
  377. LengthPercentage stroke_width { Length::make_px(1) };
  378. CSS::TextAnchor text_anchor { InitialValues::text_anchor() };
  379. Vector<ShadowData> text_shadow;
  380. CSS::MathShift math_shift { InitialValues::math_shift() };
  381. CSS::MathStyle math_style { InitialValues::math_style() };
  382. int math_depth { InitialValues::math_depth() };
  383. } m_inherited;
  384. struct {
  385. AspectRatio aspect_ratio { InitialValues::aspect_ratio() };
  386. CSS::Float float_ { InitialValues::float_() };
  387. CSS::Clear clear { InitialValues::clear() };
  388. CSS::Clip clip { InitialValues::clip() };
  389. CSS::Display display { InitialValues::display() };
  390. Optional<int> z_index;
  391. // FIXME: Store this as flags in a u8.
  392. Vector<CSS::TextDecorationLine> text_decoration_line { InitialValues::text_decoration_line() };
  393. CSS::LengthPercentage text_decoration_thickness { InitialValues::text_decoration_thickness() };
  394. CSS::TextDecorationStyle text_decoration_style { InitialValues::text_decoration_style() };
  395. Color text_decoration_color { InitialValues::color() };
  396. CSS::Position position { InitialValues::position() };
  397. CSS::Size width { InitialValues::width() };
  398. CSS::Size min_width { InitialValues::min_width() };
  399. CSS::Size max_width { InitialValues::max_width() };
  400. CSS::Size height { InitialValues::height() };
  401. CSS::Size min_height { InitialValues::min_height() };
  402. CSS::Size max_height { InitialValues::max_height() };
  403. CSS::LengthBox inset { InitialValues::inset() };
  404. CSS::LengthBox margin { InitialValues::margin() };
  405. CSS::LengthBox padding { InitialValues::padding() };
  406. CSS::BackdropFilter backdrop_filter { InitialValues::backdrop_filter() };
  407. BorderData border_left;
  408. BorderData border_top;
  409. BorderData border_right;
  410. BorderData border_bottom;
  411. BorderRadiusData border_bottom_left_radius;
  412. BorderRadiusData border_bottom_right_radius;
  413. BorderRadiusData border_top_left_radius;
  414. BorderRadiusData border_top_right_radius;
  415. Color background_color { InitialValues::background_color() };
  416. Vector<BackgroundLayerData> background_layers;
  417. CSS::FlexDirection flex_direction { InitialValues::flex_direction() };
  418. CSS::FlexWrap flex_wrap { InitialValues::flex_wrap() };
  419. CSS::FlexBasis flex_basis { InitialValues::flex_basis() };
  420. float flex_grow { InitialValues::flex_grow() };
  421. float flex_shrink { InitialValues::flex_shrink() };
  422. int order { InitialValues::order() };
  423. CSS::AlignContent align_content { InitialValues::align_content() };
  424. CSS::AlignItems align_items { InitialValues::align_items() };
  425. CSS::AlignSelf align_self { InitialValues::align_self() };
  426. CSS::Appearance appearance { InitialValues::appearance() };
  427. CSS::JustifyContent justify_content { InitialValues::justify_content() };
  428. CSS::JustifyItems justify_items { InitialValues::justify_items() };
  429. CSS::JustifySelf justify_self { InitialValues::justify_self() };
  430. CSS::Overflow overflow_x { InitialValues::overflow() };
  431. CSS::Overflow overflow_y { InitialValues::overflow() };
  432. float opacity { InitialValues::opacity() };
  433. Vector<ShadowData> box_shadow {};
  434. Vector<CSS::Transformation> transformations {};
  435. CSS::TransformOrigin transform_origin {};
  436. CSS::BoxSizing box_sizing { InitialValues::box_sizing() };
  437. CSS::ContentData content;
  438. Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align { InitialValues::vertical_align() };
  439. CSS::GridTrackSizeList grid_auto_columns;
  440. CSS::GridTrackSizeList grid_auto_rows;
  441. CSS::GridTrackSizeList grid_template_columns;
  442. CSS::GridTrackSizeList grid_template_rows;
  443. CSS::GridAutoFlow grid_auto_flow { InitialValues::grid_auto_flow() };
  444. CSS::GridTrackPlacement grid_column_end { InitialValues::grid_column_end() };
  445. CSS::GridTrackPlacement grid_column_start { InitialValues::grid_column_start() };
  446. CSS::GridTrackPlacement grid_row_end { InitialValues::grid_row_end() };
  447. CSS::GridTrackPlacement grid_row_start { InitialValues::grid_row_start() };
  448. CSS::ColumnCount column_count { InitialValues::column_count() };
  449. CSS::Size column_gap { InitialValues::column_gap() };
  450. CSS::Size row_gap { InitialValues::row_gap() };
  451. Vector<Vector<String>> grid_template_areas { InitialValues::grid_template_areas() };
  452. Gfx::Color stop_color { InitialValues::stop_color() };
  453. float stop_opacity { InitialValues::stop_opacity() };
  454. CSS::Time transition_delay { InitialValues::transition_delay() };
  455. Color outline_color { InitialValues::outline_color() };
  456. CSS::Length outline_offset { InitialValues::outline_offset() };
  457. CSS::OutlineStyle outline_style { InitialValues::outline_style() };
  458. CSS::Length outline_width { InitialValues::outline_width() };
  459. CSS::TableLayout table_layout { InitialValues::table_layout() };
  460. Optional<MaskReference> mask;
  461. } m_noninherited;
  462. };
  463. class ImmutableComputedValues final : public ComputedValues {
  464. };
  465. class MutableComputedValues final : public ComputedValues {
  466. public:
  467. void inherit_from(ComputedValues const& other)
  468. {
  469. m_inherited = static_cast<MutableComputedValues const&>(other).m_inherited;
  470. }
  471. void set_aspect_ratio(AspectRatio aspect_ratio) { m_noninherited.aspect_ratio = aspect_ratio; }
  472. void set_font_size(CSSPixels font_size) { m_inherited.font_size = font_size; }
  473. void set_font_weight(int font_weight) { m_inherited.font_weight = font_weight; }
  474. void set_font_variant(CSS::FontVariant font_variant) { m_inherited.font_variant = font_variant; }
  475. void set_border_spacing_horizontal(CSS::Length border_spacing_horizontal) { m_inherited.border_spacing_horizontal = border_spacing_horizontal; }
  476. void set_border_spacing_vertical(CSS::Length border_spacing_vertical) { m_inherited.border_spacing_vertical = border_spacing_vertical; }
  477. void set_caption_side(CSS::CaptionSide caption_side) { m_inherited.caption_side = caption_side; }
  478. void set_color(Color color) { m_inherited.color = color; }
  479. void set_clip(CSS::Clip const& clip) { m_noninherited.clip = clip; }
  480. void set_content(ContentData const& content) { m_noninherited.content = content; }
  481. void set_cursor(CSS::Cursor cursor) { m_inherited.cursor = cursor; }
  482. void set_image_rendering(CSS::ImageRendering value) { m_inherited.image_rendering = value; }
  483. void set_pointer_events(CSS::PointerEvents value) { m_inherited.pointer_events = value; }
  484. void set_background_color(Color color) { m_noninherited.background_color = color; }
  485. void set_background_layers(Vector<BackgroundLayerData>&& layers) { m_noninherited.background_layers = move(layers); }
  486. void set_float(CSS::Float value) { m_noninherited.float_ = value; }
  487. void set_clear(CSS::Clear value) { m_noninherited.clear = value; }
  488. void set_z_index(Optional<int> value) { m_noninherited.z_index = value; }
  489. void set_text_align(CSS::TextAlign text_align) { m_inherited.text_align = text_align; }
  490. void set_text_justify(CSS::TextJustify text_justify) { m_inherited.text_justify = text_justify; }
  491. void set_text_decoration_line(Vector<CSS::TextDecorationLine> value) { m_noninherited.text_decoration_line = move(value); }
  492. void set_text_decoration_thickness(CSS::LengthPercentage value) { m_noninherited.text_decoration_thickness = move(value); }
  493. void set_text_decoration_style(CSS::TextDecorationStyle value) { m_noninherited.text_decoration_style = value; }
  494. void set_text_decoration_color(Color value) { m_noninherited.text_decoration_color = value; }
  495. void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
  496. void set_text_shadow(Vector<ShadowData>&& value) { m_inherited.text_shadow = move(value); }
  497. void set_text_indent(CSS::LengthPercentage value) { m_inherited.text_indent = move(value); }
  498. void set_position(CSS::Position position) { m_noninherited.position = position; }
  499. void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
  500. void set_width(CSS::Size const& width) { m_noninherited.width = width; }
  501. void set_min_width(CSS::Size const& width) { m_noninherited.min_width = width; }
  502. void set_max_width(CSS::Size const& width) { m_noninherited.max_width = width; }
  503. void set_height(CSS::Size const& height) { m_noninherited.height = height; }
  504. void set_min_height(CSS::Size const& height) { m_noninherited.min_height = height; }
  505. void set_max_height(CSS::Size const& height) { m_noninherited.max_height = height; }
  506. void set_inset(CSS::LengthBox const& inset) { m_noninherited.inset = inset; }
  507. void set_margin(const CSS::LengthBox& margin) { m_noninherited.margin = margin; }
  508. void set_padding(const CSS::LengthBox& padding) { m_noninherited.padding = padding; }
  509. void set_overflow_x(CSS::Overflow value) { m_noninherited.overflow_x = value; }
  510. void set_overflow_y(CSS::Overflow value) { m_noninherited.overflow_y = value; }
  511. void set_list_style_type(CSS::ListStyleType value) { m_inherited.list_style_type = value; }
  512. void set_list_style_position(CSS::ListStylePosition value) { m_inherited.list_style_position = value; }
  513. void set_display(CSS::Display value) { m_noninherited.display = value; }
  514. void set_backdrop_filter(CSS::BackdropFilter backdrop_filter) { m_noninherited.backdrop_filter = move(backdrop_filter); }
  515. void set_border_bottom_left_radius(CSS::BorderRadiusData value) { m_noninherited.border_bottom_left_radius = move(value); }
  516. void set_border_bottom_right_radius(CSS::BorderRadiusData value) { m_noninherited.border_bottom_right_radius = move(value); }
  517. void set_border_top_left_radius(CSS::BorderRadiusData value) { m_noninherited.border_top_left_radius = move(value); }
  518. void set_border_top_right_radius(CSS::BorderRadiusData value) { m_noninherited.border_top_right_radius = move(value); }
  519. BorderData& border_left() { return m_noninherited.border_left; }
  520. BorderData& border_top() { return m_noninherited.border_top; }
  521. BorderData& border_right() { return m_noninherited.border_right; }
  522. BorderData& border_bottom() { return m_noninherited.border_bottom; }
  523. void set_flex_direction(CSS::FlexDirection value) { m_noninherited.flex_direction = value; }
  524. void set_flex_wrap(CSS::FlexWrap value) { m_noninherited.flex_wrap = value; }
  525. void set_flex_basis(FlexBasis value) { m_noninherited.flex_basis = move(value); }
  526. void set_flex_grow(float value) { m_noninherited.flex_grow = value; }
  527. void set_flex_shrink(float value) { m_noninherited.flex_shrink = value; }
  528. void set_order(int value) { m_noninherited.order = value; }
  529. void set_accent_color(Color value) { m_inherited.accent_color = value; }
  530. void set_align_content(CSS::AlignContent value) { m_noninherited.align_content = value; }
  531. void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; }
  532. void set_align_self(CSS::AlignSelf value) { m_noninherited.align_self = value; }
  533. void set_appearance(CSS::Appearance value) { m_noninherited.appearance = value; }
  534. void set_opacity(float value) { m_noninherited.opacity = value; }
  535. void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
  536. void set_justify_items(CSS::JustifyItems value) { m_noninherited.justify_items = value; }
  537. void set_justify_self(CSS::JustifySelf value) { m_noninherited.justify_self = value; }
  538. void set_box_shadow(Vector<ShadowData>&& value) { m_noninherited.box_shadow = move(value); }
  539. void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); }
  540. void set_transform_origin(CSS::TransformOrigin value) { m_noninherited.transform_origin = value; }
  541. void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; }
  542. void set_vertical_align(Variant<CSS::VerticalAlign, CSS::LengthPercentage> value) { m_noninherited.vertical_align = move(value); }
  543. void set_visibility(CSS::Visibility value) { m_inherited.visibility = value; }
  544. void set_grid_auto_columns(CSS::GridTrackSizeList value) { m_noninherited.grid_auto_columns = move(value); }
  545. void set_grid_auto_rows(CSS::GridTrackSizeList value) { m_noninherited.grid_auto_rows = move(value); }
  546. void set_grid_template_columns(CSS::GridTrackSizeList value) { m_noninherited.grid_template_columns = move(value); }
  547. void set_grid_template_rows(CSS::GridTrackSizeList value) { m_noninherited.grid_template_rows = move(value); }
  548. void set_grid_column_end(CSS::GridTrackPlacement value) { m_noninherited.grid_column_end = value; }
  549. void set_grid_column_start(CSS::GridTrackPlacement value) { m_noninherited.grid_column_start = value; }
  550. void set_grid_row_end(CSS::GridTrackPlacement value) { m_noninherited.grid_row_end = value; }
  551. void set_grid_row_start(CSS::GridTrackPlacement value) { m_noninherited.grid_row_start = value; }
  552. void set_column_count(CSS::ColumnCount value) { m_noninherited.column_count = value; }
  553. void set_column_gap(CSS::Size const& column_gap) { m_noninherited.column_gap = column_gap; }
  554. void set_row_gap(CSS::Size const& row_gap) { m_noninherited.row_gap = row_gap; }
  555. void set_border_collapse(CSS::BorderCollapse const& border_collapse) { m_inherited.border_collapse = border_collapse; }
  556. void set_grid_template_areas(Vector<Vector<String>> const& grid_template_areas) { m_noninherited.grid_template_areas = grid_template_areas; }
  557. void set_grid_auto_flow(CSS::GridAutoFlow grid_auto_flow) { m_noninherited.grid_auto_flow = grid_auto_flow; }
  558. void set_transition_delay(CSS::Time const& transition_delay) { m_noninherited.transition_delay = transition_delay; }
  559. void set_table_layout(CSS::TableLayout value) { m_noninherited.table_layout = value; }
  560. void set_quotes(CSS::QuotesData value) { m_inherited.quotes = value; }
  561. void set_fill(SVGPaint value) { m_inherited.fill = value; }
  562. void set_stroke(SVGPaint value) { m_inherited.stroke = value; }
  563. void set_fill_rule(CSS::FillRule value) { m_inherited.fill_rule = value; }
  564. void set_fill_opacity(float value) { m_inherited.fill_opacity = value; }
  565. void set_stroke_opacity(float value) { m_inherited.stroke_opacity = value; }
  566. void set_stroke_width(LengthPercentage value) { m_inherited.stroke_width = value; }
  567. void set_stop_color(Color value) { m_noninherited.stop_color = value; }
  568. void set_stop_opacity(float value) { m_noninherited.stop_opacity = value; }
  569. void set_text_anchor(CSS::TextAnchor value) { m_inherited.text_anchor = value; }
  570. void set_outline_color(Color value) { m_noninherited.outline_color = value; }
  571. void set_outline_offset(CSS::Length value) { m_noninherited.outline_offset = value; }
  572. void set_outline_style(CSS::OutlineStyle value) { m_noninherited.outline_style = value; }
  573. void set_outline_width(CSS::Length value) { m_noninherited.outline_width = value; }
  574. void set_mask(MaskReference value) { m_noninherited.mask = value; }
  575. void set_math_shift(CSS::MathShift value) { m_inherited.math_shift = value; }
  576. void set_math_style(CSS::MathStyle value) { m_inherited.math_style = value; }
  577. void set_math_depth(int value) { m_inherited.math_depth = value; }
  578. };
  579. }