ComputedValues.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  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 <LibWeb/CSS/BackdropFilter.h>
  9. #include <LibWeb/CSS/CalculatedOr.h>
  10. #include <LibWeb/CSS/Clip.h>
  11. #include <LibWeb/CSS/Display.h>
  12. #include <LibWeb/CSS/GridTrackPlacement.h>
  13. #include <LibWeb/CSS/GridTrackSize.h>
  14. #include <LibWeb/CSS/LengthBox.h>
  15. #include <LibWeb/CSS/PercentageOr.h>
  16. #include <LibWeb/CSS/Size.h>
  17. #include <LibWeb/CSS/StyleValues/AbstractImageStyleValue.h>
  18. #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
  19. #include <LibWeb/CSS/TransformFunctions.h>
  20. namespace Web::CSS {
  21. class InitialValues {
  22. public:
  23. static float font_size() { return 16; }
  24. static int font_weight() { return 400; }
  25. static CSS::FontVariant font_variant() { return CSS::FontVariant::Normal; }
  26. static CSS::Float float_() { return CSS::Float::None; }
  27. static CSS::Clear clear() { return CSS::Clear::None; }
  28. static CSS::Clip clip() { return CSS::Clip::make_auto(); }
  29. static CSS::Cursor cursor() { return CSS::Cursor::Auto; }
  30. static CSS::WhiteSpace white_space() { return CSS::WhiteSpace::Normal; }
  31. static CSS::TextAlign text_align() { return CSS::TextAlign::Left; }
  32. static CSS::TextJustify text_justify() { return CSS::TextJustify::Auto; }
  33. static CSS::Position position() { return CSS::Position::Static; }
  34. static CSS::TextDecorationLine text_decoration_line() { return CSS::TextDecorationLine::None; }
  35. static CSS::Length text_decoration_thickness() { return Length::make_auto(); }
  36. static CSS::TextDecorationStyle text_decoration_style() { return CSS::TextDecorationStyle::Solid; }
  37. static CSS::TextTransform text_transform() { return CSS::TextTransform::None; }
  38. static CSS::LengthPercentage text_indent() { return CSS::Length::make_px(0); }
  39. static CSS::Display display() { return CSS::Display { CSS::Display::Outside::Inline, CSS::Display::Inside::Flow }; }
  40. static Color color() { return Color::Black; }
  41. static Color stop_color() { return Color::Black; }
  42. static CSS::BackdropFilter backdrop_filter() { return BackdropFilter::make_none(); }
  43. static Color background_color() { return Color::Transparent; }
  44. static CSS::ListStyleType list_style_type() { return CSS::ListStyleType::Disc; }
  45. static CSS::Visibility visibility() { return CSS::Visibility::Visible; }
  46. static CSS::FlexDirection flex_direction() { return CSS::FlexDirection::Row; }
  47. static CSS::FlexWrap flex_wrap() { return CSS::FlexWrap::Nowrap; }
  48. static CSS::ImageRendering image_rendering() { return CSS::ImageRendering::Auto; }
  49. static CSS::JustifyContent justify_content() { return CSS::JustifyContent::FlexStart; }
  50. static CSS::AlignContent align_content() { return CSS::AlignContent::Stretch; }
  51. static CSS::AlignItems align_items() { return CSS::AlignItems::Stretch; }
  52. static CSS::AlignSelf align_self() { return CSS::AlignSelf::Auto; }
  53. static CSS::Appearance appearance() { return CSS::Appearance::Auto; }
  54. static CSS::Overflow overflow() { return CSS::Overflow::Visible; }
  55. static CSS::BoxSizing box_sizing() { return CSS::BoxSizing::ContentBox; }
  56. static CSS::PointerEvents pointer_events() { return CSS::PointerEvents::Auto; }
  57. static float flex_grow() { return 0.0f; }
  58. static float flex_shrink() { return 1.0f; }
  59. static int order() { return 0; }
  60. static float opacity() { return 1.0f; }
  61. static float fill_opacity() { return 1.0f; }
  62. static float stroke_opacity() { return 1.0f; }
  63. static float stop_opacity() { return 1.0f; }
  64. static CSS::Length border_radius() { return Length::make_px(0); }
  65. static Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align() { return CSS::VerticalAlign::Baseline; }
  66. static CSS::LengthBox inset() { return { CSS::Length::make_auto(), CSS::Length::make_auto(), CSS::Length::make_auto(), CSS::Length::make_auto() }; }
  67. 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) }; }
  68. 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) }; }
  69. static CSS::Size width() { return CSS::Size::make_auto(); }
  70. static CSS::Size min_width() { return CSS::Size::make_auto(); }
  71. static CSS::Size max_width() { return CSS::Size::make_none(); }
  72. static CSS::Size height() { return CSS::Size::make_auto(); }
  73. static CSS::Size min_height() { return CSS::Size::make_auto(); }
  74. static CSS::Size max_height() { return CSS::Size::make_none(); }
  75. static CSS::GridTrackSizeList grid_template_columns() { return CSS::GridTrackSizeList::make_auto(); }
  76. static CSS::GridTrackSizeList grid_template_rows() { return CSS::GridTrackSizeList::make_auto(); }
  77. static CSS::GridTrackPlacement grid_column_end() { return CSS::GridTrackPlacement::make_auto(); }
  78. static CSS::GridTrackPlacement grid_column_start() { return CSS::GridTrackPlacement::make_auto(); }
  79. static CSS::GridTrackPlacement grid_row_end() { return CSS::GridTrackPlacement::make_auto(); }
  80. static CSS::GridTrackPlacement grid_row_start() { return CSS::GridTrackPlacement::make_auto(); }
  81. static CSS::Size column_gap() { return CSS::Size::make_auto(); }
  82. static CSS::Size row_gap() { return CSS::Size::make_auto(); }
  83. static CSS::BorderCollapse border_collapse() { return CSS::BorderCollapse::Separate; }
  84. static Vector<Vector<String>> grid_template_areas() { return {}; }
  85. };
  86. enum class BackgroundSize {
  87. Contain,
  88. Cover,
  89. LengthPercentage,
  90. };
  91. // https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
  92. class SVGPaint {
  93. public:
  94. SVGPaint(Color color)
  95. : m_value(color)
  96. {
  97. }
  98. SVGPaint(AK::URL const& url)
  99. : m_value(url)
  100. {
  101. }
  102. bool is_color() const { return m_value.has<Color>(); }
  103. bool is_url() const { return m_value.has<AK::URL>(); }
  104. Color as_color() const { return m_value.get<Color>(); }
  105. AK::URL const& as_url() const { return m_value.get<AK::URL>(); }
  106. private:
  107. Variant<AK::URL, Color> m_value;
  108. };
  109. struct BackgroundLayerData {
  110. RefPtr<CSS::AbstractImageStyleValue const> background_image { nullptr };
  111. CSS::BackgroundAttachment attachment { CSS::BackgroundAttachment::Scroll };
  112. CSS::BackgroundBox origin { CSS::BackgroundBox::PaddingBox };
  113. CSS::BackgroundBox clip { CSS::BackgroundBox::BorderBox };
  114. CSS::PositionEdge position_edge_x { CSS::PositionEdge::Left };
  115. CSS::LengthPercentage position_offset_x { CSS::Length::make_px(0) };
  116. CSS::PositionEdge position_edge_y { CSS::PositionEdge::Top };
  117. CSS::LengthPercentage position_offset_y { CSS::Length::make_px(0) };
  118. CSS::BackgroundSize size_type { CSS::BackgroundSize::LengthPercentage };
  119. CSS::LengthPercentage size_x { CSS::Length::make_auto() };
  120. CSS::LengthPercentage size_y { CSS::Length::make_auto() };
  121. CSS::Repeat repeat_x { CSS::Repeat::Repeat };
  122. CSS::Repeat repeat_y { CSS::Repeat::Repeat };
  123. };
  124. struct BorderData {
  125. public:
  126. Color color { Color::Transparent };
  127. CSS::LineStyle line_style { CSS::LineStyle::None };
  128. double width { 0 };
  129. bool operator==(BorderData const&) const = default;
  130. };
  131. using TransformValue = Variant<CSS::AngleOrCalculated, CSS::LengthPercentage, float>;
  132. struct Transformation {
  133. CSS::TransformFunction function;
  134. Vector<TransformValue> values;
  135. };
  136. struct TransformOrigin {
  137. CSS::LengthPercentage x { Percentage(50) };
  138. CSS::LengthPercentage y { Percentage(50) };
  139. };
  140. enum class FlexBasis {
  141. Content,
  142. LengthPercentage,
  143. Auto,
  144. };
  145. struct FlexBasisData {
  146. CSS::FlexBasis type { CSS::FlexBasis::Auto };
  147. Optional<CSS::LengthPercentage> length_percentage;
  148. };
  149. struct ShadowData {
  150. Color color {};
  151. CSS::Length offset_x { Length::make_px(0) };
  152. CSS::Length offset_y { Length::make_px(0) };
  153. CSS::Length blur_radius { Length::make_px(0) };
  154. CSS::Length spread_distance { Length::make_px(0) };
  155. CSS::ShadowPlacement placement { CSS::ShadowPlacement::Outer };
  156. };
  157. struct ContentData {
  158. enum class Type {
  159. Normal,
  160. None,
  161. String,
  162. } type { Type::Normal };
  163. // FIXME: Data is a list of identifiers, strings and image values.
  164. String data {};
  165. String alt_text {};
  166. };
  167. struct BorderRadiusData {
  168. CSS::LengthPercentage horizontal_radius { InitialValues::border_radius() };
  169. CSS::LengthPercentage vertical_radius { InitialValues::border_radius() };
  170. };
  171. // FIXME: Find a better place for this helper.
  172. inline Gfx::Painter::ScalingMode to_gfx_scaling_mode(CSS::ImageRendering css_value, Gfx::IntRect source, Gfx::IntRect target)
  173. {
  174. switch (css_value) {
  175. case CSS::ImageRendering::Auto:
  176. case CSS::ImageRendering::HighQuality:
  177. case CSS::ImageRendering::Smooth:
  178. if (target.width() < source.width() || target.height() < source.height())
  179. return Gfx::Painter::ScalingMode::BoxSampling;
  180. return Gfx::Painter::ScalingMode::BilinearBlend;
  181. case CSS::ImageRendering::CrispEdges:
  182. return Gfx::Painter::ScalingMode::NearestNeighbor;
  183. case CSS::ImageRendering::Pixelated:
  184. return Gfx::Painter::ScalingMode::SmoothPixels;
  185. }
  186. VERIFY_NOT_REACHED();
  187. }
  188. class ComputedValues {
  189. public:
  190. CSS::Float float_() const { return m_noninherited.float_; }
  191. CSS::Clear clear() const { return m_noninherited.clear; }
  192. CSS::Clip clip() const { return m_noninherited.clip; }
  193. CSS::Cursor cursor() const { return m_inherited.cursor; }
  194. CSS::ContentData content() const { return m_noninherited.content; }
  195. CSS::PointerEvents pointer_events() const { return m_inherited.pointer_events; }
  196. CSS::Display display() const { return m_noninherited.display; }
  197. Optional<int> const& z_index() const { return m_noninherited.z_index; }
  198. CSS::TextAlign text_align() const { return m_inherited.text_align; }
  199. CSS::TextJustify text_justify() const { return m_inherited.text_justify; }
  200. CSS::LengthPercentage const& text_indent() const { return m_inherited.text_indent; }
  201. Vector<CSS::TextDecorationLine> const& text_decoration_line() const { return m_noninherited.text_decoration_line; }
  202. CSS::LengthPercentage const& text_decoration_thickness() const { return m_noninherited.text_decoration_thickness; }
  203. CSS::TextDecorationStyle text_decoration_style() const { return m_noninherited.text_decoration_style; }
  204. Color text_decoration_color() const { return m_noninherited.text_decoration_color; }
  205. CSS::TextTransform text_transform() const { return m_inherited.text_transform; }
  206. Vector<ShadowData> const& text_shadow() const { return m_noninherited.text_shadow; }
  207. CSS::Position position() const { return m_noninherited.position; }
  208. CSS::WhiteSpace white_space() const { return m_inherited.white_space; }
  209. CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; }
  210. CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; }
  211. FlexBasisData const& flex_basis() const { return m_noninherited.flex_basis; }
  212. float flex_grow() const { return m_noninherited.flex_grow; }
  213. float flex_shrink() const { return m_noninherited.flex_shrink; }
  214. int order() const { return m_noninherited.order; }
  215. Optional<Color> accent_color() const { return m_inherited.accent_color; }
  216. CSS::AlignContent align_content() const { return m_noninherited.align_content; }
  217. CSS::AlignItems align_items() const { return m_noninherited.align_items; }
  218. CSS::AlignSelf align_self() const { return m_noninherited.align_self; }
  219. CSS::Appearance appearance() const { return m_noninherited.appearance; }
  220. float opacity() const { return m_noninherited.opacity; }
  221. CSS::Visibility visibility() const { return m_inherited.visibility; }
  222. CSS::ImageRendering image_rendering() const { return m_inherited.image_rendering; }
  223. CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
  224. CSS::BackdropFilter const& backdrop_filter() const { return m_noninherited.backdrop_filter; }
  225. Vector<ShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
  226. CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
  227. CSS::Size const& width() const { return m_noninherited.width; }
  228. CSS::Size const& min_width() const { return m_noninherited.min_width; }
  229. CSS::Size const& max_width() const { return m_noninherited.max_width; }
  230. CSS::Size const& height() const { return m_noninherited.height; }
  231. CSS::Size const& min_height() const { return m_noninherited.min_height; }
  232. CSS::Size const& max_height() const { return m_noninherited.max_height; }
  233. Variant<CSS::VerticalAlign, CSS::LengthPercentage> const& vertical_align() const { return m_noninherited.vertical_align; }
  234. CSS::GridTrackSizeList const& grid_auto_columns() const { return m_noninherited.grid_auto_columns; }
  235. CSS::GridTrackSizeList const& grid_auto_rows() const { return m_noninherited.grid_auto_rows; }
  236. CSS::GridTrackSizeList const& grid_template_columns() const { return m_noninherited.grid_template_columns; }
  237. CSS::GridTrackSizeList const& grid_template_rows() const { return m_noninherited.grid_template_rows; }
  238. CSS::GridTrackPlacement const& grid_column_end() const { return m_noninherited.grid_column_end; }
  239. CSS::GridTrackPlacement const& grid_column_start() const { return m_noninherited.grid_column_start; }
  240. CSS::GridTrackPlacement const& grid_row_end() const { return m_noninherited.grid_row_end; }
  241. CSS::GridTrackPlacement const& grid_row_start() const { return m_noninherited.grid_row_start; }
  242. CSS::Size const& column_gap() const { return m_noninherited.column_gap; }
  243. CSS::Size const& row_gap() const { return m_noninherited.row_gap; }
  244. CSS::BorderCollapse border_collapse() const { return m_noninherited.border_collapse; }
  245. Vector<Vector<String>> const& grid_template_areas() const { return m_noninherited.grid_template_areas; }
  246. CSS::LengthBox const& inset() const { return m_noninherited.inset; }
  247. const CSS::LengthBox& margin() const { return m_noninherited.margin; }
  248. const CSS::LengthBox& padding() const { return m_noninherited.padding; }
  249. BorderData const& border_left() const { return m_noninherited.border_left; }
  250. BorderData const& border_top() const { return m_noninherited.border_top; }
  251. BorderData const& border_right() const { return m_noninherited.border_right; }
  252. BorderData const& border_bottom() const { return m_noninherited.border_bottom; }
  253. const CSS::BorderRadiusData& border_bottom_left_radius() const { return m_noninherited.border_bottom_left_radius; }
  254. const CSS::BorderRadiusData& border_bottom_right_radius() const { return m_noninherited.border_bottom_right_radius; }
  255. const CSS::BorderRadiusData& border_top_left_radius() const { return m_noninherited.border_top_left_radius; }
  256. const CSS::BorderRadiusData& border_top_right_radius() const { return m_noninherited.border_top_right_radius; }
  257. CSS::Overflow overflow_x() const { return m_noninherited.overflow_x; }
  258. CSS::Overflow overflow_y() const { return m_noninherited.overflow_y; }
  259. Color color() const { return m_inherited.color; }
  260. Color background_color() const { return m_noninherited.background_color; }
  261. Vector<BackgroundLayerData> const& background_layers() const { return m_noninherited.background_layers; }
  262. CSS::ListStyleType list_style_type() const { return m_inherited.list_style_type; }
  263. Optional<SVGPaint> const& fill() const { return m_inherited.fill; }
  264. Optional<SVGPaint> const& stroke() const { return m_inherited.stroke; }
  265. float fill_opacity() const { return m_inherited.fill_opacity; }
  266. float stroke_opacity() const { return m_inherited.stroke_opacity; }
  267. Optional<LengthPercentage> const& stroke_width() const { return m_inherited.stroke_width; }
  268. Color stop_color() const { return m_noninherited.stop_color; }
  269. float stop_opacity() const { return m_noninherited.stop_opacity; }
  270. Vector<CSS::Transformation> const& transformations() const { return m_noninherited.transformations; }
  271. CSS::TransformOrigin const& transform_origin() const { return m_noninherited.transform_origin; }
  272. float font_size() const { return m_inherited.font_size; }
  273. int font_weight() const { return m_inherited.font_weight; }
  274. CSS::FontVariant font_variant() const { return m_inherited.font_variant; }
  275. ComputedValues clone_inherited_values() const
  276. {
  277. ComputedValues clone;
  278. clone.m_inherited = m_inherited;
  279. return clone;
  280. }
  281. protected:
  282. struct {
  283. float font_size { InitialValues::font_size() };
  284. int font_weight { InitialValues::font_weight() };
  285. CSS::FontVariant font_variant { InitialValues::font_variant() };
  286. Color color { InitialValues::color() };
  287. Optional<Color> accent_color {};
  288. CSS::Cursor cursor { InitialValues::cursor() };
  289. CSS::ImageRendering image_rendering { InitialValues::image_rendering() };
  290. CSS::PointerEvents pointer_events { InitialValues::pointer_events() };
  291. CSS::TextAlign text_align { InitialValues::text_align() };
  292. CSS::TextJustify text_justify { InitialValues::text_justify() };
  293. CSS::TextTransform text_transform { InitialValues::text_transform() };
  294. CSS::LengthPercentage text_indent { InitialValues::text_indent() };
  295. CSS::WhiteSpace white_space { InitialValues::white_space() };
  296. CSS::ListStyleType list_style_type { InitialValues::list_style_type() };
  297. CSS::Visibility visibility { InitialValues::visibility() };
  298. Optional<SVGPaint> fill;
  299. Optional<SVGPaint> stroke;
  300. float fill_opacity { InitialValues::fill_opacity() };
  301. float stroke_opacity { InitialValues::stroke_opacity() };
  302. Optional<LengthPercentage> stroke_width;
  303. } m_inherited;
  304. struct {
  305. CSS::Float float_ { InitialValues::float_() };
  306. CSS::Clear clear { InitialValues::clear() };
  307. CSS::Clip clip { InitialValues::clip() };
  308. CSS::Display display { InitialValues::display() };
  309. Optional<int> z_index;
  310. // FIXME: Store this as flags in a u8.
  311. Vector<CSS::TextDecorationLine> text_decoration_line { InitialValues::text_decoration_line() };
  312. CSS::LengthPercentage text_decoration_thickness { InitialValues::text_decoration_thickness() };
  313. CSS::TextDecorationStyle text_decoration_style { InitialValues::text_decoration_style() };
  314. Color text_decoration_color { InitialValues::color() };
  315. Vector<ShadowData> text_shadow {};
  316. CSS::Position position { InitialValues::position() };
  317. CSS::Size width { InitialValues::width() };
  318. CSS::Size min_width { InitialValues::min_width() };
  319. CSS::Size max_width { InitialValues::max_width() };
  320. CSS::Size height { InitialValues::height() };
  321. CSS::Size min_height { InitialValues::min_height() };
  322. CSS::Size max_height { InitialValues::max_height() };
  323. CSS::LengthBox inset { InitialValues::inset() };
  324. CSS::LengthBox margin { InitialValues::margin() };
  325. CSS::LengthBox padding { InitialValues::padding() };
  326. CSS::BackdropFilter backdrop_filter { InitialValues::backdrop_filter() };
  327. BorderData border_left;
  328. BorderData border_top;
  329. BorderData border_right;
  330. BorderData border_bottom;
  331. BorderRadiusData border_bottom_left_radius;
  332. BorderRadiusData border_bottom_right_radius;
  333. BorderRadiusData border_top_left_radius;
  334. BorderRadiusData border_top_right_radius;
  335. Color background_color { InitialValues::background_color() };
  336. Vector<BackgroundLayerData> background_layers;
  337. CSS::FlexDirection flex_direction { InitialValues::flex_direction() };
  338. CSS::FlexWrap flex_wrap { InitialValues::flex_wrap() };
  339. CSS::FlexBasisData flex_basis {};
  340. float flex_grow { InitialValues::flex_grow() };
  341. float flex_shrink { InitialValues::flex_shrink() };
  342. int order { InitialValues::order() };
  343. CSS::AlignContent align_content { InitialValues::align_content() };
  344. CSS::AlignItems align_items { InitialValues::align_items() };
  345. CSS::AlignSelf align_self { InitialValues::align_self() };
  346. CSS::Appearance appearance { InitialValues::appearance() };
  347. CSS::JustifyContent justify_content { InitialValues::justify_content() };
  348. CSS::Overflow overflow_x { InitialValues::overflow() };
  349. CSS::Overflow overflow_y { InitialValues::overflow() };
  350. float opacity { InitialValues::opacity() };
  351. Vector<ShadowData> box_shadow {};
  352. Vector<CSS::Transformation> transformations {};
  353. CSS::TransformOrigin transform_origin {};
  354. CSS::BoxSizing box_sizing { InitialValues::box_sizing() };
  355. CSS::ContentData content;
  356. Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align { InitialValues::vertical_align() };
  357. CSS::GridTrackSizeList grid_auto_columns;
  358. CSS::GridTrackSizeList grid_auto_rows;
  359. CSS::GridTrackSizeList grid_template_columns;
  360. CSS::GridTrackSizeList grid_template_rows;
  361. CSS::GridTrackPlacement grid_column_end { InitialValues::grid_column_end() };
  362. CSS::GridTrackPlacement grid_column_start { InitialValues::grid_column_start() };
  363. CSS::GridTrackPlacement grid_row_end { InitialValues::grid_row_end() };
  364. CSS::GridTrackPlacement grid_row_start { InitialValues::grid_row_start() };
  365. CSS::Size column_gap { InitialValues::column_gap() };
  366. CSS::Size row_gap { InitialValues::row_gap() };
  367. CSS::BorderCollapse border_collapse { InitialValues::border_collapse() };
  368. Vector<Vector<String>> grid_template_areas { InitialValues::grid_template_areas() };
  369. Gfx::Color stop_color { InitialValues::stop_color() };
  370. float stop_opacity { InitialValues::stop_opacity() };
  371. } m_noninherited;
  372. };
  373. class ImmutableComputedValues final : public ComputedValues {
  374. };
  375. class MutableComputedValues final : public ComputedValues {
  376. public:
  377. void set_font_size(float font_size) { m_inherited.font_size = font_size; }
  378. void set_font_weight(int font_weight) { m_inherited.font_weight = font_weight; }
  379. void set_font_variant(CSS::FontVariant font_variant) { m_inherited.font_variant = font_variant; }
  380. void set_color(Color color) { m_inherited.color = color; }
  381. void set_clip(CSS::Clip const& clip) { m_noninherited.clip = clip; }
  382. void set_content(ContentData const& content) { m_noninherited.content = content; }
  383. void set_cursor(CSS::Cursor cursor) { m_inherited.cursor = cursor; }
  384. void set_image_rendering(CSS::ImageRendering value) { m_inherited.image_rendering = value; }
  385. void set_pointer_events(CSS::PointerEvents value) { m_inherited.pointer_events = value; }
  386. void set_background_color(Color color) { m_noninherited.background_color = color; }
  387. void set_background_layers(Vector<BackgroundLayerData>&& layers) { m_noninherited.background_layers = move(layers); }
  388. void set_float(CSS::Float value) { m_noninherited.float_ = value; }
  389. void set_clear(CSS::Clear value) { m_noninherited.clear = value; }
  390. void set_z_index(Optional<int> value) { m_noninherited.z_index = value; }
  391. void set_text_align(CSS::TextAlign text_align) { m_inherited.text_align = text_align; }
  392. void set_text_justify(CSS::TextJustify text_justify) { m_inherited.text_justify = text_justify; }
  393. void set_text_decoration_line(Vector<CSS::TextDecorationLine> value) { m_noninherited.text_decoration_line = move(value); }
  394. void set_text_decoration_thickness(CSS::LengthPercentage value) { m_noninherited.text_decoration_thickness = move(value); }
  395. void set_text_decoration_style(CSS::TextDecorationStyle value) { m_noninherited.text_decoration_style = value; }
  396. void set_text_decoration_color(Color value) { m_noninherited.text_decoration_color = value; }
  397. void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
  398. void set_text_shadow(Vector<ShadowData>&& value) { m_noninherited.text_shadow = move(value); }
  399. void set_text_indent(CSS::LengthPercentage value) { m_inherited.text_indent = move(value); }
  400. void set_position(CSS::Position position) { m_noninherited.position = position; }
  401. void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
  402. void set_width(CSS::Size const& width) { m_noninherited.width = width; }
  403. void set_min_width(CSS::Size const& width) { m_noninherited.min_width = width; }
  404. void set_max_width(CSS::Size const& width) { m_noninherited.max_width = width; }
  405. void set_height(CSS::Size const& height) { m_noninherited.height = height; }
  406. void set_min_height(CSS::Size const& height) { m_noninherited.min_height = height; }
  407. void set_max_height(CSS::Size const& height) { m_noninherited.max_height = height; }
  408. void set_inset(CSS::LengthBox const& inset) { m_noninherited.inset = inset; }
  409. void set_margin(const CSS::LengthBox& margin) { m_noninherited.margin = margin; }
  410. void set_padding(const CSS::LengthBox& padding) { m_noninherited.padding = padding; }
  411. void set_overflow_x(CSS::Overflow value) { m_noninherited.overflow_x = value; }
  412. void set_overflow_y(CSS::Overflow value) { m_noninherited.overflow_y = value; }
  413. void set_list_style_type(CSS::ListStyleType value) { m_inherited.list_style_type = value; }
  414. void set_display(CSS::Display value) { m_noninherited.display = value; }
  415. void set_backdrop_filter(CSS::BackdropFilter backdrop_filter) { m_noninherited.backdrop_filter = move(backdrop_filter); }
  416. void set_border_bottom_left_radius(CSS::BorderRadiusData value) { m_noninherited.border_bottom_left_radius = move(value); }
  417. void set_border_bottom_right_radius(CSS::BorderRadiusData value) { m_noninherited.border_bottom_right_radius = move(value); }
  418. void set_border_top_left_radius(CSS::BorderRadiusData value) { m_noninherited.border_top_left_radius = move(value); }
  419. void set_border_top_right_radius(CSS::BorderRadiusData value) { m_noninherited.border_top_right_radius = move(value); }
  420. BorderData& border_left() { return m_noninherited.border_left; }
  421. BorderData& border_top() { return m_noninherited.border_top; }
  422. BorderData& border_right() { return m_noninherited.border_right; }
  423. BorderData& border_bottom() { return m_noninherited.border_bottom; }
  424. void set_flex_direction(CSS::FlexDirection value) { m_noninherited.flex_direction = value; }
  425. void set_flex_wrap(CSS::FlexWrap value) { m_noninherited.flex_wrap = value; }
  426. void set_flex_basis(FlexBasisData value) { m_noninherited.flex_basis = move(value); }
  427. void set_flex_grow(float value) { m_noninherited.flex_grow = value; }
  428. void set_flex_shrink(float value) { m_noninherited.flex_shrink = value; }
  429. void set_order(int value) { m_noninherited.order = value; }
  430. void set_accent_color(Color value) { m_inherited.accent_color = value; }
  431. void set_align_content(CSS::AlignContent value) { m_noninherited.align_content = value; }
  432. void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; }
  433. void set_align_self(CSS::AlignSelf value) { m_noninherited.align_self = value; }
  434. void set_appearance(CSS::Appearance value) { m_noninherited.appearance = value; }
  435. void set_opacity(float value) { m_noninherited.opacity = value; }
  436. void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
  437. void set_box_shadow(Vector<ShadowData>&& value) { m_noninherited.box_shadow = move(value); }
  438. void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); }
  439. void set_transform_origin(CSS::TransformOrigin value) { m_noninherited.transform_origin = value; }
  440. void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; }
  441. void set_vertical_align(Variant<CSS::VerticalAlign, CSS::LengthPercentage> value) { m_noninherited.vertical_align = move(value); }
  442. void set_visibility(CSS::Visibility value) { m_inherited.visibility = value; }
  443. void set_grid_auto_columns(CSS::GridTrackSizeList value) { m_noninherited.grid_auto_columns = move(value); }
  444. void set_grid_auto_rows(CSS::GridTrackSizeList value) { m_noninherited.grid_auto_rows = move(value); }
  445. void set_grid_template_columns(CSS::GridTrackSizeList value) { m_noninherited.grid_template_columns = move(value); }
  446. void set_grid_template_rows(CSS::GridTrackSizeList value) { m_noninherited.grid_template_rows = move(value); }
  447. void set_grid_column_end(CSS::GridTrackPlacement value) { m_noninherited.grid_column_end = value; }
  448. void set_grid_column_start(CSS::GridTrackPlacement value) { m_noninherited.grid_column_start = value; }
  449. void set_grid_row_end(CSS::GridTrackPlacement value) { m_noninherited.grid_row_end = value; }
  450. void set_grid_row_start(CSS::GridTrackPlacement value) { m_noninherited.grid_row_start = value; }
  451. void set_column_gap(CSS::Size const& column_gap) { m_noninherited.column_gap = column_gap; }
  452. void set_row_gap(CSS::Size const& row_gap) { m_noninherited.row_gap = row_gap; }
  453. void set_border_collapse(CSS::BorderCollapse const& border_collapse) { m_noninherited.border_collapse = border_collapse; }
  454. void set_grid_template_areas(Vector<Vector<String>> const& grid_template_areas) { m_noninherited.grid_template_areas = grid_template_areas; }
  455. void set_fill(SVGPaint value) { m_inherited.fill = value; }
  456. void set_stroke(SVGPaint value) { m_inherited.stroke = value; }
  457. void set_fill_opacity(float value) { m_inherited.fill_opacity = value; }
  458. void set_stroke_opacity(float value) { m_inherited.stroke_opacity = value; }
  459. void set_stroke_width(LengthPercentage value) { m_inherited.stroke_width = value; }
  460. void set_stop_color(Color value) { m_noninherited.stop_color = value; }
  461. void set_stop_opacity(float value) { m_noninherited.stop_opacity = value; }
  462. };
  463. }