ComputedValues.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  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. float width { 0 };
  129. };
  130. using TransformValue = Variant<CSS::AngleOrCalculated, CSS::LengthPercentage, float>;
  131. struct Transformation {
  132. CSS::TransformFunction function;
  133. Vector<TransformValue> values;
  134. };
  135. struct TransformOrigin {
  136. CSS::LengthPercentage x { Percentage(50) };
  137. CSS::LengthPercentage y { Percentage(50) };
  138. };
  139. enum class FlexBasis {
  140. Content,
  141. LengthPercentage,
  142. Auto,
  143. };
  144. struct FlexBasisData {
  145. CSS::FlexBasis type { CSS::FlexBasis::Auto };
  146. Optional<CSS::LengthPercentage> length_percentage;
  147. };
  148. struct ShadowData {
  149. Color color {};
  150. CSS::Length offset_x { Length::make_px(0) };
  151. CSS::Length offset_y { Length::make_px(0) };
  152. CSS::Length blur_radius { Length::make_px(0) };
  153. CSS::Length spread_distance { Length::make_px(0) };
  154. CSS::ShadowPlacement placement { CSS::ShadowPlacement::Outer };
  155. };
  156. struct ContentData {
  157. enum class Type {
  158. Normal,
  159. None,
  160. String,
  161. } type { Type::Normal };
  162. // FIXME: Data is a list of identifiers, strings and image values.
  163. String data {};
  164. String alt_text {};
  165. };
  166. struct BorderRadiusData {
  167. CSS::LengthPercentage horizontal_radius { InitialValues::border_radius() };
  168. CSS::LengthPercentage vertical_radius { InitialValues::border_radius() };
  169. };
  170. // FIXME: Find a better place for this helper.
  171. inline Gfx::Painter::ScalingMode to_gfx_scaling_mode(CSS::ImageRendering css_value, Gfx::IntRect source, Gfx::IntRect target)
  172. {
  173. switch (css_value) {
  174. case CSS::ImageRendering::Auto:
  175. case CSS::ImageRendering::HighQuality:
  176. case CSS::ImageRendering::Smooth:
  177. if (target.width() < source.width() || target.height() < source.height())
  178. return Gfx::Painter::ScalingMode::BoxSampling;
  179. return Gfx::Painter::ScalingMode::BilinearBlend;
  180. case CSS::ImageRendering::CrispEdges:
  181. return Gfx::Painter::ScalingMode::NearestNeighbor;
  182. case CSS::ImageRendering::Pixelated:
  183. return Gfx::Painter::ScalingMode::SmoothPixels;
  184. }
  185. VERIFY_NOT_REACHED();
  186. }
  187. class ComputedValues {
  188. public:
  189. CSS::Float float_() const { return m_noninherited.float_; }
  190. CSS::Clear clear() const { return m_noninherited.clear; }
  191. CSS::Clip clip() const { return m_noninherited.clip; }
  192. CSS::Cursor cursor() const { return m_inherited.cursor; }
  193. CSS::ContentData content() const { return m_noninherited.content; }
  194. CSS::PointerEvents pointer_events() const { return m_inherited.pointer_events; }
  195. CSS::Display display() const { return m_noninherited.display; }
  196. Optional<int> const& z_index() const { return m_noninherited.z_index; }
  197. CSS::TextAlign text_align() const { return m_inherited.text_align; }
  198. CSS::TextJustify text_justify() const { return m_inherited.text_justify; }
  199. CSS::LengthPercentage const& text_indent() const { return m_inherited.text_indent; }
  200. Vector<CSS::TextDecorationLine> const& text_decoration_line() const { return m_noninherited.text_decoration_line; }
  201. CSS::LengthPercentage const& text_decoration_thickness() const { return m_noninherited.text_decoration_thickness; }
  202. CSS::TextDecorationStyle text_decoration_style() const { return m_noninherited.text_decoration_style; }
  203. Color text_decoration_color() const { return m_noninherited.text_decoration_color; }
  204. CSS::TextTransform text_transform() const { return m_inherited.text_transform; }
  205. Vector<ShadowData> const& text_shadow() const { return m_noninherited.text_shadow; }
  206. CSS::Position position() const { return m_noninherited.position; }
  207. CSS::WhiteSpace white_space() const { return m_inherited.white_space; }
  208. CSS::FlexDirection flex_direction() const { return m_noninherited.flex_direction; }
  209. CSS::FlexWrap flex_wrap() const { return m_noninherited.flex_wrap; }
  210. FlexBasisData const& flex_basis() const { return m_noninherited.flex_basis; }
  211. float flex_grow() const { return m_noninherited.flex_grow; }
  212. float flex_shrink() const { return m_noninherited.flex_shrink; }
  213. int order() const { return m_noninherited.order; }
  214. Optional<Color> accent_color() const { return m_inherited.accent_color; }
  215. CSS::AlignContent align_content() const { return m_noninherited.align_content; }
  216. CSS::AlignItems align_items() const { return m_noninherited.align_items; }
  217. CSS::AlignSelf align_self() const { return m_noninherited.align_self; }
  218. CSS::Appearance appearance() const { return m_noninherited.appearance; }
  219. float opacity() const { return m_noninherited.opacity; }
  220. CSS::Visibility visibility() const { return m_inherited.visibility; }
  221. CSS::ImageRendering image_rendering() const { return m_inherited.image_rendering; }
  222. CSS::JustifyContent justify_content() const { return m_noninherited.justify_content; }
  223. CSS::BackdropFilter const& backdrop_filter() const { return m_noninherited.backdrop_filter; }
  224. Vector<ShadowData> const& box_shadow() const { return m_noninherited.box_shadow; }
  225. CSS::BoxSizing box_sizing() const { return m_noninherited.box_sizing; }
  226. CSS::Size const& width() const { return m_noninherited.width; }
  227. CSS::Size const& min_width() const { return m_noninherited.min_width; }
  228. CSS::Size const& max_width() const { return m_noninherited.max_width; }
  229. CSS::Size const& height() const { return m_noninherited.height; }
  230. CSS::Size const& min_height() const { return m_noninherited.min_height; }
  231. CSS::Size const& max_height() const { return m_noninherited.max_height; }
  232. Variant<CSS::VerticalAlign, CSS::LengthPercentage> const& vertical_align() const { return m_noninherited.vertical_align; }
  233. CSS::GridTrackSizeList const& grid_template_columns() const { return m_noninherited.grid_template_columns; }
  234. CSS::GridTrackSizeList const& grid_template_rows() const { return m_noninherited.grid_template_rows; }
  235. CSS::GridTrackPlacement const& grid_column_end() const { return m_noninherited.grid_column_end; }
  236. CSS::GridTrackPlacement const& grid_column_start() const { return m_noninherited.grid_column_start; }
  237. CSS::GridTrackPlacement const& grid_row_end() const { return m_noninherited.grid_row_end; }
  238. CSS::GridTrackPlacement const& grid_row_start() const { return m_noninherited.grid_row_start; }
  239. CSS::Size const& column_gap() const { return m_noninherited.column_gap; }
  240. CSS::Size const& row_gap() const { return m_noninherited.row_gap; }
  241. CSS::BorderCollapse border_collapse() const { return m_noninherited.border_collapse; }
  242. Vector<Vector<String>> const& grid_template_areas() const { return m_noninherited.grid_template_areas; }
  243. CSS::LengthBox const& inset() const { return m_noninherited.inset; }
  244. const CSS::LengthBox& margin() const { return m_noninherited.margin; }
  245. const CSS::LengthBox& padding() const { return m_noninherited.padding; }
  246. BorderData const& border_left() const { return m_noninherited.border_left; }
  247. BorderData const& border_top() const { return m_noninherited.border_top; }
  248. BorderData const& border_right() const { return m_noninherited.border_right; }
  249. BorderData const& border_bottom() const { return m_noninherited.border_bottom; }
  250. const CSS::BorderRadiusData& border_bottom_left_radius() const { return m_noninherited.border_bottom_left_radius; }
  251. const CSS::BorderRadiusData& border_bottom_right_radius() const { return m_noninherited.border_bottom_right_radius; }
  252. const CSS::BorderRadiusData& border_top_left_radius() const { return m_noninherited.border_top_left_radius; }
  253. const CSS::BorderRadiusData& border_top_right_radius() const { return m_noninherited.border_top_right_radius; }
  254. CSS::Overflow overflow_x() const { return m_noninherited.overflow_x; }
  255. CSS::Overflow overflow_y() const { return m_noninherited.overflow_y; }
  256. Color color() const { return m_inherited.color; }
  257. Color background_color() const { return m_noninherited.background_color; }
  258. Vector<BackgroundLayerData> const& background_layers() const { return m_noninherited.background_layers; }
  259. CSS::ListStyleType list_style_type() const { return m_inherited.list_style_type; }
  260. Optional<SVGPaint> const& fill() const { return m_inherited.fill; }
  261. Optional<SVGPaint> const& stroke() const { return m_inherited.stroke; }
  262. float fill_opacity() const { return m_inherited.fill_opacity; }
  263. float stroke_opacity() const { return m_inherited.stroke_opacity; }
  264. Optional<LengthPercentage> const& stroke_width() const { return m_inherited.stroke_width; }
  265. Color stop_color() const { return m_noninherited.stop_color; }
  266. float stop_opacity() const { return m_noninherited.stop_opacity; }
  267. Vector<CSS::Transformation> const& transformations() const { return m_noninherited.transformations; }
  268. CSS::TransformOrigin const& transform_origin() const { return m_noninherited.transform_origin; }
  269. float font_size() const { return m_inherited.font_size; }
  270. int font_weight() const { return m_inherited.font_weight; }
  271. CSS::FontVariant font_variant() const { return m_inherited.font_variant; }
  272. ComputedValues clone_inherited_values() const
  273. {
  274. ComputedValues clone;
  275. clone.m_inherited = m_inherited;
  276. return clone;
  277. }
  278. protected:
  279. struct {
  280. float font_size { InitialValues::font_size() };
  281. int font_weight { InitialValues::font_weight() };
  282. CSS::FontVariant font_variant { InitialValues::font_variant() };
  283. Color color { InitialValues::color() };
  284. Optional<Color> accent_color {};
  285. CSS::Cursor cursor { InitialValues::cursor() };
  286. CSS::ImageRendering image_rendering { InitialValues::image_rendering() };
  287. CSS::PointerEvents pointer_events { InitialValues::pointer_events() };
  288. CSS::TextAlign text_align { InitialValues::text_align() };
  289. CSS::TextJustify text_justify { InitialValues::text_justify() };
  290. CSS::TextTransform text_transform { InitialValues::text_transform() };
  291. CSS::LengthPercentage text_indent { InitialValues::text_indent() };
  292. CSS::WhiteSpace white_space { InitialValues::white_space() };
  293. CSS::ListStyleType list_style_type { InitialValues::list_style_type() };
  294. CSS::Visibility visibility { InitialValues::visibility() };
  295. Optional<SVGPaint> fill;
  296. Optional<SVGPaint> stroke;
  297. float fill_opacity { InitialValues::fill_opacity() };
  298. float stroke_opacity { InitialValues::stroke_opacity() };
  299. Optional<LengthPercentage> stroke_width;
  300. } m_inherited;
  301. struct {
  302. CSS::Float float_ { InitialValues::float_() };
  303. CSS::Clear clear { InitialValues::clear() };
  304. CSS::Clip clip { InitialValues::clip() };
  305. CSS::Display display { InitialValues::display() };
  306. Optional<int> z_index;
  307. // FIXME: Store this as flags in a u8.
  308. Vector<CSS::TextDecorationLine> text_decoration_line { InitialValues::text_decoration_line() };
  309. CSS::LengthPercentage text_decoration_thickness { InitialValues::text_decoration_thickness() };
  310. CSS::TextDecorationStyle text_decoration_style { InitialValues::text_decoration_style() };
  311. Color text_decoration_color { InitialValues::color() };
  312. Vector<ShadowData> text_shadow {};
  313. CSS::Position position { InitialValues::position() };
  314. CSS::Size width { InitialValues::width() };
  315. CSS::Size min_width { InitialValues::min_width() };
  316. CSS::Size max_width { InitialValues::max_width() };
  317. CSS::Size height { InitialValues::height() };
  318. CSS::Size min_height { InitialValues::min_height() };
  319. CSS::Size max_height { InitialValues::max_height() };
  320. CSS::LengthBox inset { InitialValues::inset() };
  321. CSS::LengthBox margin { InitialValues::margin() };
  322. CSS::LengthBox padding { InitialValues::padding() };
  323. CSS::BackdropFilter backdrop_filter { InitialValues::backdrop_filter() };
  324. BorderData border_left;
  325. BorderData border_top;
  326. BorderData border_right;
  327. BorderData border_bottom;
  328. BorderRadiusData border_bottom_left_radius;
  329. BorderRadiusData border_bottom_right_radius;
  330. BorderRadiusData border_top_left_radius;
  331. BorderRadiusData border_top_right_radius;
  332. Color background_color { InitialValues::background_color() };
  333. Vector<BackgroundLayerData> background_layers;
  334. CSS::FlexDirection flex_direction { InitialValues::flex_direction() };
  335. CSS::FlexWrap flex_wrap { InitialValues::flex_wrap() };
  336. CSS::FlexBasisData flex_basis {};
  337. float flex_grow { InitialValues::flex_grow() };
  338. float flex_shrink { InitialValues::flex_shrink() };
  339. int order { InitialValues::order() };
  340. CSS::AlignContent align_content { InitialValues::align_content() };
  341. CSS::AlignItems align_items { InitialValues::align_items() };
  342. CSS::AlignSelf align_self { InitialValues::align_self() };
  343. CSS::Appearance appearance { InitialValues::appearance() };
  344. CSS::JustifyContent justify_content { InitialValues::justify_content() };
  345. CSS::Overflow overflow_x { InitialValues::overflow() };
  346. CSS::Overflow overflow_y { InitialValues::overflow() };
  347. float opacity { InitialValues::opacity() };
  348. Vector<ShadowData> box_shadow {};
  349. Vector<CSS::Transformation> transformations {};
  350. CSS::TransformOrigin transform_origin {};
  351. CSS::BoxSizing box_sizing { InitialValues::box_sizing() };
  352. CSS::ContentData content;
  353. Variant<CSS::VerticalAlign, CSS::LengthPercentage> vertical_align { InitialValues::vertical_align() };
  354. CSS::GridTrackSizeList grid_template_columns;
  355. CSS::GridTrackSizeList grid_template_rows;
  356. CSS::GridTrackPlacement grid_column_end { InitialValues::grid_column_end() };
  357. CSS::GridTrackPlacement grid_column_start { InitialValues::grid_column_start() };
  358. CSS::GridTrackPlacement grid_row_end { InitialValues::grid_row_end() };
  359. CSS::GridTrackPlacement grid_row_start { InitialValues::grid_row_start() };
  360. CSS::Size column_gap { InitialValues::column_gap() };
  361. CSS::Size row_gap { InitialValues::row_gap() };
  362. CSS::BorderCollapse border_collapse { InitialValues::border_collapse() };
  363. Vector<Vector<String>> grid_template_areas { InitialValues::grid_template_areas() };
  364. Gfx::Color stop_color { InitialValues::stop_color() };
  365. float stop_opacity { InitialValues::stop_opacity() };
  366. } m_noninherited;
  367. };
  368. class ImmutableComputedValues final : public ComputedValues {
  369. };
  370. class MutableComputedValues final : public ComputedValues {
  371. public:
  372. void set_font_size(float font_size) { m_inherited.font_size = font_size; }
  373. void set_font_weight(int font_weight) { m_inherited.font_weight = font_weight; }
  374. void set_font_variant(CSS::FontVariant font_variant) { m_inherited.font_variant = font_variant; }
  375. void set_color(Color color) { m_inherited.color = color; }
  376. void set_clip(CSS::Clip const& clip) { m_noninherited.clip = clip; }
  377. void set_content(ContentData const& content) { m_noninherited.content = content; }
  378. void set_cursor(CSS::Cursor cursor) { m_inherited.cursor = cursor; }
  379. void set_image_rendering(CSS::ImageRendering value) { m_inherited.image_rendering = value; }
  380. void set_pointer_events(CSS::PointerEvents value) { m_inherited.pointer_events = value; }
  381. void set_background_color(Color color) { m_noninherited.background_color = color; }
  382. void set_background_layers(Vector<BackgroundLayerData>&& layers) { m_noninherited.background_layers = move(layers); }
  383. void set_float(CSS::Float value) { m_noninherited.float_ = value; }
  384. void set_clear(CSS::Clear value) { m_noninherited.clear = value; }
  385. void set_z_index(Optional<int> value) { m_noninherited.z_index = value; }
  386. void set_text_align(CSS::TextAlign text_align) { m_inherited.text_align = text_align; }
  387. void set_text_justify(CSS::TextJustify text_justify) { m_inherited.text_justify = text_justify; }
  388. void set_text_decoration_line(Vector<CSS::TextDecorationLine> value) { m_noninherited.text_decoration_line = move(value); }
  389. void set_text_decoration_thickness(CSS::LengthPercentage value) { m_noninherited.text_decoration_thickness = move(value); }
  390. void set_text_decoration_style(CSS::TextDecorationStyle value) { m_noninherited.text_decoration_style = value; }
  391. void set_text_decoration_color(Color value) { m_noninherited.text_decoration_color = value; }
  392. void set_text_transform(CSS::TextTransform value) { m_inherited.text_transform = value; }
  393. void set_text_shadow(Vector<ShadowData>&& value) { m_noninherited.text_shadow = move(value); }
  394. void set_text_indent(CSS::LengthPercentage value) { m_inherited.text_indent = move(value); }
  395. void set_position(CSS::Position position) { m_noninherited.position = position; }
  396. void set_white_space(CSS::WhiteSpace value) { m_inherited.white_space = value; }
  397. void set_width(CSS::Size const& width) { m_noninherited.width = width; }
  398. void set_min_width(CSS::Size const& width) { m_noninherited.min_width = width; }
  399. void set_max_width(CSS::Size const& width) { m_noninherited.max_width = width; }
  400. void set_height(CSS::Size const& height) { m_noninherited.height = height; }
  401. void set_min_height(CSS::Size const& height) { m_noninherited.min_height = height; }
  402. void set_max_height(CSS::Size const& height) { m_noninherited.max_height = height; }
  403. void set_inset(CSS::LengthBox const& inset) { m_noninherited.inset = inset; }
  404. void set_margin(const CSS::LengthBox& margin) { m_noninherited.margin = margin; }
  405. void set_padding(const CSS::LengthBox& padding) { m_noninherited.padding = padding; }
  406. void set_overflow_x(CSS::Overflow value) { m_noninherited.overflow_x = value; }
  407. void set_overflow_y(CSS::Overflow value) { m_noninherited.overflow_y = value; }
  408. void set_list_style_type(CSS::ListStyleType value) { m_inherited.list_style_type = value; }
  409. void set_display(CSS::Display value) { m_noninherited.display = value; }
  410. void set_backdrop_filter(CSS::BackdropFilter backdrop_filter) { m_noninherited.backdrop_filter = move(backdrop_filter); }
  411. void set_border_bottom_left_radius(CSS::BorderRadiusData value) { m_noninherited.border_bottom_left_radius = move(value); }
  412. void set_border_bottom_right_radius(CSS::BorderRadiusData value) { m_noninherited.border_bottom_right_radius = move(value); }
  413. void set_border_top_left_radius(CSS::BorderRadiusData value) { m_noninherited.border_top_left_radius = move(value); }
  414. void set_border_top_right_radius(CSS::BorderRadiusData value) { m_noninherited.border_top_right_radius = move(value); }
  415. BorderData& border_left() { return m_noninherited.border_left; }
  416. BorderData& border_top() { return m_noninherited.border_top; }
  417. BorderData& border_right() { return m_noninherited.border_right; }
  418. BorderData& border_bottom() { return m_noninherited.border_bottom; }
  419. void set_flex_direction(CSS::FlexDirection value) { m_noninherited.flex_direction = value; }
  420. void set_flex_wrap(CSS::FlexWrap value) { m_noninherited.flex_wrap = value; }
  421. void set_flex_basis(FlexBasisData value) { m_noninherited.flex_basis = move(value); }
  422. void set_flex_grow(float value) { m_noninherited.flex_grow = value; }
  423. void set_flex_shrink(float value) { m_noninherited.flex_shrink = value; }
  424. void set_order(int value) { m_noninherited.order = value; }
  425. void set_accent_color(Color value) { m_inherited.accent_color = value; }
  426. void set_align_content(CSS::AlignContent value) { m_noninherited.align_content = value; }
  427. void set_align_items(CSS::AlignItems value) { m_noninherited.align_items = value; }
  428. void set_align_self(CSS::AlignSelf value) { m_noninherited.align_self = value; }
  429. void set_appearance(CSS::Appearance value) { m_noninherited.appearance = value; }
  430. void set_opacity(float value) { m_noninherited.opacity = value; }
  431. void set_justify_content(CSS::JustifyContent value) { m_noninherited.justify_content = value; }
  432. void set_box_shadow(Vector<ShadowData>&& value) { m_noninherited.box_shadow = move(value); }
  433. void set_transformations(Vector<CSS::Transformation> value) { m_noninherited.transformations = move(value); }
  434. void set_transform_origin(CSS::TransformOrigin value) { m_noninherited.transform_origin = value; }
  435. void set_box_sizing(CSS::BoxSizing value) { m_noninherited.box_sizing = value; }
  436. void set_vertical_align(Variant<CSS::VerticalAlign, CSS::LengthPercentage> value) { m_noninherited.vertical_align = move(value); }
  437. void set_visibility(CSS::Visibility value) { m_inherited.visibility = value; }
  438. void set_grid_template_columns(CSS::GridTrackSizeList value) { m_noninherited.grid_template_columns = move(value); }
  439. void set_grid_template_rows(CSS::GridTrackSizeList value) { m_noninherited.grid_template_rows = move(value); }
  440. void set_grid_column_end(CSS::GridTrackPlacement value) { m_noninherited.grid_column_end = value; }
  441. void set_grid_column_start(CSS::GridTrackPlacement value) { m_noninherited.grid_column_start = value; }
  442. void set_grid_row_end(CSS::GridTrackPlacement value) { m_noninherited.grid_row_end = value; }
  443. void set_grid_row_start(CSS::GridTrackPlacement value) { m_noninherited.grid_row_start = value; }
  444. void set_column_gap(CSS::Size const& column_gap) { m_noninherited.column_gap = column_gap; }
  445. void set_row_gap(CSS::Size const& row_gap) { m_noninherited.row_gap = row_gap; }
  446. void set_border_collapse(CSS::BorderCollapse const& border_collapse) { m_noninherited.border_collapse = border_collapse; }
  447. void set_grid_template_areas(Vector<Vector<String>> const& grid_template_areas) { m_noninherited.grid_template_areas = grid_template_areas; }
  448. void set_fill(SVGPaint value) { m_inherited.fill = value; }
  449. void set_stroke(SVGPaint value) { m_inherited.stroke = value; }
  450. void set_fill_opacity(float value) { m_inherited.fill_opacity = value; }
  451. void set_stroke_opacity(float value) { m_inherited.stroke_opacity = value; }
  452. void set_stroke_width(LengthPercentage value) { m_inherited.stroke_width = value; }
  453. void set_stop_color(Color value) { m_noninherited.stop_color = value; }
  454. void set_stop_opacity(float value) { m_noninherited.stop_opacity = value; }
  455. };
  456. }