ComputedValues.h 43 KB

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