StyleProperties.cpp 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. /*
  2. * Copyright (c) 2018-2024, Andreas Kling <andreas@ladybird.org>
  3. * Copyright (c) 2021-2024, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/TypeCasts.h>
  8. #include <LibCore/DirIterator.h>
  9. #include <LibWeb/CSS/Clip.h>
  10. #include <LibWeb/CSS/StyleProperties.h>
  11. #include <LibWeb/CSS/StyleValues/AngleStyleValue.h>
  12. #include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
  13. #include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
  14. #include <LibWeb/CSS/StyleValues/CounterDefinitionsStyleValue.h>
  15. #include <LibWeb/CSS/StyleValues/CounterStyleValue.h>
  16. #include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
  17. #include <LibWeb/CSS/StyleValues/GridAutoFlowStyleValue.h>
  18. #include <LibWeb/CSS/StyleValues/GridTemplateAreaStyleValue.h>
  19. #include <LibWeb/CSS/StyleValues/GridTrackPlacementStyleValue.h>
  20. #include <LibWeb/CSS/StyleValues/GridTrackSizeListStyleValue.h>
  21. #include <LibWeb/CSS/StyleValues/IntegerStyleValue.h>
  22. #include <LibWeb/CSS/StyleValues/LengthStyleValue.h>
  23. #include <LibWeb/CSS/StyleValues/MathDepthStyleValue.h>
  24. #include <LibWeb/CSS/StyleValues/NumberStyleValue.h>
  25. #include <LibWeb/CSS/StyleValues/PercentageStyleValue.h>
  26. #include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
  27. #include <LibWeb/CSS/StyleValues/RectStyleValue.h>
  28. #include <LibWeb/CSS/StyleValues/ScrollbarGutterStyleValue.h>
  29. #include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
  30. #include <LibWeb/CSS/StyleValues/StringStyleValue.h>
  31. #include <LibWeb/CSS/StyleValues/StyleValueList.h>
  32. #include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
  33. #include <LibWeb/Layout/BlockContainer.h>
  34. #include <LibWeb/Layout/Node.h>
  35. #include <LibWeb/Platform/FontPlugin.h>
  36. namespace Web::CSS {
  37. NonnullRefPtr<StyleProperties::Data> StyleProperties::Data::clone() const
  38. {
  39. auto clone = adopt_ref(*new StyleProperties::Data);
  40. clone->m_property_values = m_property_values;
  41. clone->m_animated_property_values = m_animated_property_values;
  42. clone->m_property_important = m_property_important;
  43. clone->m_property_inherited = m_property_inherited;
  44. clone->m_font_list = m_font_list;
  45. clone->m_line_height = m_line_height;
  46. clone->m_animation_name_source = m_animation_name_source;
  47. clone->m_math_depth = m_math_depth;
  48. return clone;
  49. }
  50. NonnullRefPtr<StyleProperties> StyleProperties::clone() const
  51. {
  52. auto cloned = adopt_ref(*new StyleProperties);
  53. cloned->m_data = m_data;
  54. return cloned;
  55. }
  56. bool StyleProperties::is_property_important(CSS::PropertyID property_id) const
  57. {
  58. size_t n = to_underlying(property_id);
  59. return m_data->m_property_important[n / 8] & (1 << (n % 8));
  60. }
  61. void StyleProperties::set_property_important(CSS::PropertyID property_id, Important important)
  62. {
  63. size_t n = to_underlying(property_id);
  64. if (important == Important::Yes)
  65. m_data->m_property_important[n / 8] |= (1 << (n % 8));
  66. else
  67. m_data->m_property_important[n / 8] &= ~(1 << (n % 8));
  68. }
  69. bool StyleProperties::is_property_inherited(CSS::PropertyID property_id) const
  70. {
  71. size_t n = to_underlying(property_id);
  72. return m_data->m_property_inherited[n / 8] & (1 << (n % 8));
  73. }
  74. void StyleProperties::set_property_inherited(CSS::PropertyID property_id, Inherited inherited)
  75. {
  76. size_t n = to_underlying(property_id);
  77. if (inherited == Inherited::Yes)
  78. m_data->m_property_inherited[n / 8] |= (1 << (n % 8));
  79. else
  80. m_data->m_property_inherited[n / 8] &= ~(1 << (n % 8));
  81. }
  82. void StyleProperties::set_property(CSS::PropertyID id, NonnullRefPtr<CSSStyleValue const> value, Inherited inherited, Important important)
  83. {
  84. m_data->m_property_values[to_underlying(id)] = move(value);
  85. set_property_important(id, important);
  86. set_property_inherited(id, inherited);
  87. }
  88. void StyleProperties::revert_property(CSS::PropertyID id, StyleProperties const& style_for_revert)
  89. {
  90. m_data->m_property_values[to_underlying(id)] = style_for_revert.m_data->m_property_values[to_underlying(id)];
  91. set_property_important(id, style_for_revert.is_property_important(id) ? Important::Yes : Important::No);
  92. set_property_inherited(id, style_for_revert.is_property_inherited(id) ? Inherited::Yes : Inherited::No);
  93. }
  94. void StyleProperties::set_animated_property(CSS::PropertyID id, NonnullRefPtr<CSSStyleValue const> value)
  95. {
  96. m_data->m_animated_property_values.set(id, move(value));
  97. }
  98. void StyleProperties::reset_animated_properties()
  99. {
  100. m_data->m_animated_property_values.clear();
  101. }
  102. NonnullRefPtr<CSSStyleValue const> StyleProperties::property(CSS::PropertyID property_id) const
  103. {
  104. if (auto animated_value = m_data->m_animated_property_values.get(property_id).value_or(nullptr))
  105. return *animated_value;
  106. // By the time we call this method, all properties have values assigned.
  107. return *m_data->m_property_values[to_underlying(property_id)];
  108. }
  109. RefPtr<CSSStyleValue const> StyleProperties::maybe_null_property(CSS::PropertyID property_id) const
  110. {
  111. if (auto animated_value = m_data->m_animated_property_values.get(property_id).value_or(nullptr))
  112. return *animated_value;
  113. return m_data->m_property_values[to_underlying(property_id)];
  114. }
  115. CSS::Size StyleProperties::size_value(CSS::PropertyID id) const
  116. {
  117. auto value = property(id);
  118. if (value->is_keyword()) {
  119. switch (value->to_keyword()) {
  120. case Keyword::Auto:
  121. return CSS::Size::make_auto();
  122. case Keyword::MinContent:
  123. return CSS::Size::make_min_content();
  124. case Keyword::MaxContent:
  125. return CSS::Size::make_max_content();
  126. case Keyword::FitContent:
  127. return CSS::Size::make_fit_content();
  128. case Keyword::None:
  129. return CSS::Size::make_none();
  130. default:
  131. VERIFY_NOT_REACHED();
  132. }
  133. }
  134. if (value->is_math())
  135. return CSS::Size::make_calculated(const_cast<CSSMathValue&>(value->as_math()));
  136. if (value->is_percentage())
  137. return CSS::Size::make_percentage(value->as_percentage().percentage());
  138. if (value->is_length()) {
  139. auto length = value->as_length().length();
  140. if (length.is_auto())
  141. return CSS::Size::make_auto();
  142. return CSS::Size::make_length(length);
  143. }
  144. // FIXME: Support `fit-content(<length>)`
  145. dbgln("FIXME: Unsupported size value: `{}`, treating as `auto`", value->to_string());
  146. return CSS::Size::make_auto();
  147. }
  148. LengthPercentage StyleProperties::length_percentage_or_fallback(CSS::PropertyID id, LengthPercentage const& fallback) const
  149. {
  150. return length_percentage(id).value_or(fallback);
  151. }
  152. Optional<LengthPercentage> StyleProperties::length_percentage(CSS::PropertyID id) const
  153. {
  154. auto value = property(id);
  155. if (value->is_math())
  156. return LengthPercentage { const_cast<CSSMathValue&>(value->as_math()) };
  157. if (value->is_percentage())
  158. return value->as_percentage().percentage();
  159. if (value->is_length())
  160. return value->as_length().length();
  161. if (value->has_auto())
  162. return LengthPercentage { Length::make_auto() };
  163. return {};
  164. }
  165. LengthBox StyleProperties::length_box(CSS::PropertyID left_id, CSS::PropertyID top_id, CSS::PropertyID right_id, CSS::PropertyID bottom_id, const CSS::Length& default_value) const
  166. {
  167. LengthBox box;
  168. box.left() = length_percentage_or_fallback(left_id, default_value);
  169. box.top() = length_percentage_or_fallback(top_id, default_value);
  170. box.right() = length_percentage_or_fallback(right_id, default_value);
  171. box.bottom() = length_percentage_or_fallback(bottom_id, default_value);
  172. return box;
  173. }
  174. Color StyleProperties::color_or_fallback(CSS::PropertyID id, Layout::NodeWithStyle const& node, Color fallback) const
  175. {
  176. auto value = property(id);
  177. if (!value->has_color())
  178. return fallback;
  179. return value->to_color(node);
  180. }
  181. NonnullRefPtr<Gfx::Font const> StyleProperties::font_fallback(bool monospace, bool bold)
  182. {
  183. if (monospace && bold)
  184. return Platform::FontPlugin::the().default_fixed_width_font().bold_variant();
  185. if (monospace)
  186. return Platform::FontPlugin::the().default_fixed_width_font();
  187. if (bold)
  188. return Platform::FontPlugin::the().default_font().bold_variant();
  189. return Platform::FontPlugin::the().default_font();
  190. }
  191. CSSPixels StyleProperties::compute_line_height(CSSPixelRect const& viewport_rect, Length::FontMetrics const& font_metrics, Length::FontMetrics const& root_font_metrics) const
  192. {
  193. auto line_height = property(CSS::PropertyID::LineHeight);
  194. if (line_height->is_keyword() && line_height->to_keyword() == Keyword::Normal)
  195. return font_metrics.line_height;
  196. if (line_height->is_length()) {
  197. auto line_height_length = line_height->as_length().length();
  198. if (!line_height_length.is_auto())
  199. return line_height_length.to_px(viewport_rect, font_metrics, root_font_metrics);
  200. }
  201. if (line_height->is_number())
  202. return Length(line_height->as_number().number(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
  203. if (line_height->is_percentage()) {
  204. // Percentages are relative to 1em. https://www.w3.org/TR/css-inline-3/#valdef-line-height-percentage
  205. auto& percentage = line_height->as_percentage().percentage();
  206. return Length(percentage.as_fraction(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
  207. }
  208. if (line_height->is_math()) {
  209. if (line_height->as_math().resolves_to_number()) {
  210. auto resolved = line_height->as_math().resolve_number();
  211. if (!resolved.has_value()) {
  212. dbgln("FIXME: Failed to resolve calc() line-height (number): {}", line_height->as_math().to_string());
  213. return CSSPixels::nearest_value_for(m_data->m_font_list->first().pixel_metrics().line_spacing());
  214. }
  215. return Length(resolved.value(), Length::Type::Em).to_px(viewport_rect, font_metrics, root_font_metrics);
  216. }
  217. auto resolved = line_height->as_math().resolve_length(Length::ResolutionContext { viewport_rect, font_metrics, root_font_metrics });
  218. if (!resolved.has_value()) {
  219. dbgln("FIXME: Failed to resolve calc() line-height: {}", line_height->as_math().to_string());
  220. return CSSPixels::nearest_value_for(m_data->m_font_list->first().pixel_metrics().line_spacing());
  221. }
  222. return resolved->to_px(viewport_rect, font_metrics, root_font_metrics);
  223. }
  224. return font_metrics.line_height;
  225. }
  226. Optional<int> StyleProperties::z_index() const
  227. {
  228. auto value = property(CSS::PropertyID::ZIndex);
  229. if (value->has_auto())
  230. return {};
  231. if (value->is_integer()) {
  232. // Clamp z-index to the range of a signed 32-bit integer for consistency with other engines.
  233. auto integer = value->as_integer().integer();
  234. if (integer >= NumericLimits<int>::max())
  235. return NumericLimits<int>::max();
  236. if (integer <= NumericLimits<int>::min())
  237. return NumericLimits<int>::min();
  238. return static_cast<int>(integer);
  239. }
  240. return {};
  241. }
  242. float StyleProperties::resolve_opacity_value(CSSStyleValue const& value)
  243. {
  244. float unclamped_opacity = 1.0f;
  245. if (value.is_number()) {
  246. unclamped_opacity = value.as_number().number();
  247. } else if (value.is_math()) {
  248. auto& calculated = value.as_math();
  249. if (calculated.resolves_to_percentage()) {
  250. auto maybe_percentage = value.as_math().resolve_percentage();
  251. if (maybe_percentage.has_value())
  252. unclamped_opacity = maybe_percentage->as_fraction();
  253. else
  254. dbgln("Unable to resolve calc() as opacity (percentage): {}", value.to_string());
  255. } else if (calculated.resolves_to_number()) {
  256. auto maybe_number = const_cast<CSSMathValue&>(value.as_math()).resolve_number();
  257. if (maybe_number.has_value())
  258. unclamped_opacity = maybe_number.value();
  259. else
  260. dbgln("Unable to resolve calc() as opacity (number): {}", value.to_string());
  261. }
  262. } else if (value.is_percentage()) {
  263. unclamped_opacity = value.as_percentage().percentage().as_fraction();
  264. }
  265. return clamp(unclamped_opacity, 0.0f, 1.0f);
  266. }
  267. float StyleProperties::opacity() const
  268. {
  269. auto value = property(CSS::PropertyID::Opacity);
  270. return resolve_opacity_value(*value);
  271. }
  272. float StyleProperties::fill_opacity() const
  273. {
  274. auto value = property(CSS::PropertyID::FillOpacity);
  275. return resolve_opacity_value(*value);
  276. }
  277. float StyleProperties::stroke_opacity() const
  278. {
  279. auto value = property(CSS::PropertyID::StrokeOpacity);
  280. return resolve_opacity_value(*value);
  281. }
  282. float StyleProperties::stop_opacity() const
  283. {
  284. auto value = property(CSS::PropertyID::StopOpacity);
  285. return resolve_opacity_value(*value);
  286. }
  287. Optional<CSS::FillRule> StyleProperties::fill_rule() const
  288. {
  289. auto value = property(CSS::PropertyID::FillRule);
  290. return keyword_to_fill_rule(value->to_keyword());
  291. }
  292. Optional<CSS::ClipRule> StyleProperties::clip_rule() const
  293. {
  294. auto value = property(CSS::PropertyID::ClipRule);
  295. return keyword_to_fill_rule(value->to_keyword());
  296. }
  297. Optional<CSS::FlexDirection> StyleProperties::flex_direction() const
  298. {
  299. auto value = property(CSS::PropertyID::FlexDirection);
  300. return keyword_to_flex_direction(value->to_keyword());
  301. }
  302. Optional<CSS::FlexWrap> StyleProperties::flex_wrap() const
  303. {
  304. auto value = property(CSS::PropertyID::FlexWrap);
  305. return keyword_to_flex_wrap(value->to_keyword());
  306. }
  307. Optional<CSS::FlexBasis> StyleProperties::flex_basis() const
  308. {
  309. auto value = property(CSS::PropertyID::FlexBasis);
  310. if (value->is_keyword() && value->to_keyword() == CSS::Keyword::Content)
  311. return CSS::FlexBasisContent {};
  312. return size_value(CSS::PropertyID::FlexBasis);
  313. }
  314. float StyleProperties::flex_grow() const
  315. {
  316. auto value = property(CSS::PropertyID::FlexGrow);
  317. if (!value->is_number())
  318. return 0;
  319. return value->as_number().number();
  320. }
  321. float StyleProperties::flex_shrink() const
  322. {
  323. auto value = property(CSS::PropertyID::FlexShrink);
  324. if (!value->is_number())
  325. return 1;
  326. return value->as_number().number();
  327. }
  328. int StyleProperties::order() const
  329. {
  330. auto value = property(CSS::PropertyID::Order);
  331. if (!value->is_integer())
  332. return 0;
  333. return value->as_integer().integer();
  334. }
  335. Optional<CSS::ImageRendering> StyleProperties::image_rendering() const
  336. {
  337. auto value = property(CSS::PropertyID::ImageRendering);
  338. return keyword_to_image_rendering(value->to_keyword());
  339. }
  340. CSS::Length StyleProperties::border_spacing_horizontal() const
  341. {
  342. auto value = property(CSS::PropertyID::BorderSpacing);
  343. if (value->is_length())
  344. return value->as_length().length();
  345. auto const& list = value->as_value_list();
  346. return list.value_at(0, false)->as_length().length();
  347. }
  348. CSS::Length StyleProperties::border_spacing_vertical() const
  349. {
  350. auto value = property(CSS::PropertyID::BorderSpacing);
  351. if (value->is_length())
  352. return value->as_length().length();
  353. auto const& list = value->as_value_list();
  354. return list.value_at(1, false)->as_length().length();
  355. }
  356. Optional<CSS::CaptionSide> StyleProperties::caption_side() const
  357. {
  358. auto value = property(CSS::PropertyID::CaptionSide);
  359. return keyword_to_caption_side(value->to_keyword());
  360. }
  361. CSS::Clip StyleProperties::clip() const
  362. {
  363. auto value = property(CSS::PropertyID::Clip);
  364. if (!value->is_rect())
  365. return CSS::Clip::make_auto();
  366. return CSS::Clip(value->as_rect().rect());
  367. }
  368. Optional<CSS::JustifyContent> StyleProperties::justify_content() const
  369. {
  370. auto value = property(CSS::PropertyID::JustifyContent);
  371. return keyword_to_justify_content(value->to_keyword());
  372. }
  373. Optional<CSS::JustifyItems> StyleProperties::justify_items() const
  374. {
  375. auto value = property(CSS::PropertyID::JustifyItems);
  376. return keyword_to_justify_items(value->to_keyword());
  377. }
  378. Optional<CSS::JustifySelf> StyleProperties::justify_self() const
  379. {
  380. auto value = property(CSS::PropertyID::JustifySelf);
  381. return keyword_to_justify_self(value->to_keyword());
  382. }
  383. Vector<CSS::Transformation> StyleProperties::transformations_for_style_value(CSSStyleValue const& value)
  384. {
  385. if (value.is_keyword() && value.to_keyword() == CSS::Keyword::None)
  386. return {};
  387. if (!value.is_value_list())
  388. return {};
  389. auto& list = value.as_value_list();
  390. Vector<CSS::Transformation> transformations;
  391. for (auto& it : list.values()) {
  392. if (!it->is_transformation())
  393. return {};
  394. auto& transformation_style_value = it->as_transformation();
  395. auto function = transformation_style_value.transform_function();
  396. auto function_metadata = transform_function_metadata(function);
  397. Vector<TransformValue> values;
  398. size_t argument_index = 0;
  399. for (auto& transformation_value : transformation_style_value.values()) {
  400. if (transformation_value->is_math()) {
  401. auto& calculated = transformation_value->as_math();
  402. if (calculated.resolves_to_length_percentage()) {
  403. values.append(CSS::LengthPercentage { calculated });
  404. } else if (calculated.resolves_to_percentage()) {
  405. // FIXME: Maybe transform this for loop to always check the metadata for the correct types
  406. if (function_metadata.parameters[argument_index].type == TransformFunctionParameterType::NumberPercentage) {
  407. values.append(NumberPercentage { calculated.resolve_percentage().value() });
  408. } else {
  409. values.append(LengthPercentage { calculated.resolve_percentage().value() });
  410. }
  411. } else if (calculated.resolves_to_number()) {
  412. values.append({ Number(Number::Type::Number, calculated.resolve_number().value()) });
  413. } else if (calculated.resolves_to_angle()) {
  414. values.append({ calculated.resolve_angle().value() });
  415. } else {
  416. dbgln("FIXME: Unsupported calc value in transform! {}", calculated.to_string());
  417. }
  418. } else if (transformation_value->is_length()) {
  419. values.append({ transformation_value->as_length().length() });
  420. } else if (transformation_value->is_percentage()) {
  421. if (function_metadata.parameters[argument_index].type == TransformFunctionParameterType::NumberPercentage) {
  422. values.append(NumberPercentage { transformation_value->as_percentage().percentage() });
  423. } else {
  424. values.append(LengthPercentage { transformation_value->as_percentage().percentage() });
  425. }
  426. } else if (transformation_value->is_number()) {
  427. values.append({ Number(Number::Type::Number, transformation_value->as_number().number()) });
  428. } else if (transformation_value->is_angle()) {
  429. values.append({ transformation_value->as_angle().angle() });
  430. } else {
  431. dbgln("FIXME: Unsupported value in transform! {}", transformation_value->to_string());
  432. }
  433. argument_index++;
  434. }
  435. transformations.empend(function, move(values));
  436. }
  437. return transformations;
  438. }
  439. Vector<CSS::Transformation> StyleProperties::transformations() const
  440. {
  441. return transformations_for_style_value(property(CSS::PropertyID::Transform));
  442. }
  443. static Optional<LengthPercentage> length_percentage_for_style_value(CSSStyleValue const& value)
  444. {
  445. if (value.is_length())
  446. return value.as_length().length();
  447. if (value.is_percentage())
  448. return value.as_percentage().percentage();
  449. return {};
  450. }
  451. Optional<CSS::TransformBox> StyleProperties::transform_box() const
  452. {
  453. auto value = property(CSS::PropertyID::TransformBox);
  454. return keyword_to_transform_box(value->to_keyword());
  455. }
  456. CSS::TransformOrigin StyleProperties::transform_origin() const
  457. {
  458. auto value = property(CSS::PropertyID::TransformOrigin);
  459. if (!value->is_value_list() || value->as_value_list().size() != 2)
  460. return {};
  461. auto const& list = value->as_value_list();
  462. auto x_value = length_percentage_for_style_value(list.values()[0]);
  463. auto y_value = length_percentage_for_style_value(list.values()[1]);
  464. if (!x_value.has_value() || !y_value.has_value()) {
  465. return {};
  466. }
  467. return { x_value.value(), y_value.value() };
  468. }
  469. Optional<Color> StyleProperties::accent_color(Layout::NodeWithStyle const& node) const
  470. {
  471. auto value = property(CSS::PropertyID::AccentColor);
  472. if (value->has_color())
  473. return value->to_color(node);
  474. return {};
  475. }
  476. Optional<CSS::AlignContent> StyleProperties::align_content() const
  477. {
  478. auto value = property(CSS::PropertyID::AlignContent);
  479. return keyword_to_align_content(value->to_keyword());
  480. }
  481. Optional<CSS::AlignItems> StyleProperties::align_items() const
  482. {
  483. auto value = property(CSS::PropertyID::AlignItems);
  484. return keyword_to_align_items(value->to_keyword());
  485. }
  486. Optional<CSS::AlignSelf> StyleProperties::align_self() const
  487. {
  488. auto value = property(CSS::PropertyID::AlignSelf);
  489. return keyword_to_align_self(value->to_keyword());
  490. }
  491. Optional<CSS::Appearance> StyleProperties::appearance() const
  492. {
  493. auto value = property(CSS::PropertyID::Appearance);
  494. auto appearance = keyword_to_appearance(value->to_keyword());
  495. if (appearance.has_value()) {
  496. switch (*appearance) {
  497. // Note: All these compatibility values can be treated as 'auto'
  498. case CSS::Appearance::Textfield:
  499. case CSS::Appearance::MenulistButton:
  500. case CSS::Appearance::Searchfield:
  501. case CSS::Appearance::Textarea:
  502. case CSS::Appearance::PushButton:
  503. case CSS::Appearance::SliderHorizontal:
  504. case CSS::Appearance::Checkbox:
  505. case CSS::Appearance::Radio:
  506. case CSS::Appearance::SquareButton:
  507. case CSS::Appearance::Menulist:
  508. case CSS::Appearance::Listbox:
  509. case CSS::Appearance::Meter:
  510. case CSS::Appearance::ProgressBar:
  511. case CSS::Appearance::Button:
  512. appearance = CSS::Appearance::Auto;
  513. break;
  514. default:
  515. break;
  516. }
  517. }
  518. return appearance;
  519. }
  520. CSS::BackdropFilter StyleProperties::backdrop_filter() const
  521. {
  522. auto value = property(CSS::PropertyID::BackdropFilter);
  523. if (value->is_filter_value_list())
  524. return BackdropFilter(value->as_filter_value_list());
  525. return BackdropFilter::make_none();
  526. }
  527. Optional<CSS::Positioning> StyleProperties::position() const
  528. {
  529. auto value = property(CSS::PropertyID::Position);
  530. return keyword_to_positioning(value->to_keyword());
  531. }
  532. bool StyleProperties::operator==(StyleProperties const& other) const
  533. {
  534. if (m_data->m_property_values.size() != other.m_data->m_property_values.size())
  535. return false;
  536. for (size_t i = 0; i < m_data->m_property_values.size(); ++i) {
  537. auto const& my_style = m_data->m_property_values[i];
  538. auto const& other_style = other.m_data->m_property_values[i];
  539. if (!my_style) {
  540. if (other_style)
  541. return false;
  542. continue;
  543. }
  544. if (!other_style)
  545. return false;
  546. auto const& my_value = *my_style;
  547. auto const& other_value = *other_style;
  548. if (my_value.type() != other_value.type())
  549. return false;
  550. if (my_value != other_value)
  551. return false;
  552. }
  553. return true;
  554. }
  555. Optional<CSS::TextAnchor> StyleProperties::text_anchor() const
  556. {
  557. auto value = property(CSS::PropertyID::TextAnchor);
  558. return keyword_to_text_anchor(value->to_keyword());
  559. }
  560. Optional<CSS::TextAlign> StyleProperties::text_align() const
  561. {
  562. auto value = property(CSS::PropertyID::TextAlign);
  563. return keyword_to_text_align(value->to_keyword());
  564. }
  565. Optional<CSS::TextJustify> StyleProperties::text_justify() const
  566. {
  567. auto value = property(CSS::PropertyID::TextJustify);
  568. return keyword_to_text_justify(value->to_keyword());
  569. }
  570. Optional<CSS::TextOverflow> StyleProperties::text_overflow() const
  571. {
  572. auto value = property(CSS::PropertyID::TextOverflow);
  573. return keyword_to_text_overflow(value->to_keyword());
  574. }
  575. Optional<CSS::PointerEvents> StyleProperties::pointer_events() const
  576. {
  577. auto value = property(CSS::PropertyID::PointerEvents);
  578. return keyword_to_pointer_events(value->to_keyword());
  579. }
  580. Optional<CSS::WhiteSpace> StyleProperties::white_space() const
  581. {
  582. auto value = property(CSS::PropertyID::WhiteSpace);
  583. return keyword_to_white_space(value->to_keyword());
  584. }
  585. Optional<CSS::LineStyle> StyleProperties::line_style(CSS::PropertyID property_id) const
  586. {
  587. auto value = property(property_id);
  588. return keyword_to_line_style(value->to_keyword());
  589. }
  590. Optional<CSS::OutlineStyle> StyleProperties::outline_style() const
  591. {
  592. auto value = property(CSS::PropertyID::OutlineStyle);
  593. return keyword_to_outline_style(value->to_keyword());
  594. }
  595. Optional<CSS::Float> StyleProperties::float_() const
  596. {
  597. auto value = property(CSS::PropertyID::Float);
  598. return keyword_to_float(value->to_keyword());
  599. }
  600. Optional<CSS::Clear> StyleProperties::clear() const
  601. {
  602. auto value = property(CSS::PropertyID::Clear);
  603. return keyword_to_clear(value->to_keyword());
  604. }
  605. Optional<CSS::ColumnSpan> StyleProperties::column_span() const
  606. {
  607. auto value = property(CSS::PropertyID::ColumnSpan);
  608. return keyword_to_column_span(value->to_keyword());
  609. }
  610. StyleProperties::ContentDataAndQuoteNestingLevel StyleProperties::content(DOM::Element& element, u32 initial_quote_nesting_level) const
  611. {
  612. auto value = property(CSS::PropertyID::Content);
  613. auto quotes_data = quotes();
  614. auto quote_nesting_level = initial_quote_nesting_level;
  615. auto get_quote_string = [&](bool open, auto depth) {
  616. switch (quotes_data.type) {
  617. case QuotesData::Type::None:
  618. return FlyString {};
  619. case QuotesData::Type::Auto:
  620. // FIXME: "A typographically appropriate used value for quotes is automatically chosen by the UA
  621. // based on the content language of the element and/or its parent."
  622. if (open)
  623. return depth == 0 ? "“"_fly_string : "‘"_fly_string;
  624. return depth == 0 ? "”"_fly_string : "’"_fly_string;
  625. case QuotesData::Type::Specified:
  626. // If the depth is greater than the number of pairs, the last pair is repeated.
  627. auto& level = quotes_data.strings[min(depth, quotes_data.strings.size() - 1)];
  628. return open ? level[0] : level[1];
  629. }
  630. VERIFY_NOT_REACHED();
  631. };
  632. if (value->is_content()) {
  633. auto& content_style_value = value->as_content();
  634. CSS::ContentData content_data;
  635. // FIXME: The content is a list of things: strings, identifiers or functions that return strings, and images.
  636. // So it can't always be represented as a single String, but may have to be multiple boxes.
  637. // For now, we'll just assume strings since that is easiest.
  638. StringBuilder builder;
  639. for (auto const& item : content_style_value.content().values()) {
  640. if (item->is_string()) {
  641. builder.append(item->as_string().string_value());
  642. } else if (item->is_keyword()) {
  643. switch (item->to_keyword()) {
  644. case Keyword::OpenQuote:
  645. builder.append(get_quote_string(true, quote_nesting_level++));
  646. break;
  647. case Keyword::CloseQuote:
  648. // A 'close-quote' or 'no-close-quote' that would make the depth negative is in error and is ignored
  649. // (at rendering time): the depth stays at 0 and no quote mark is rendered (although the rest of the
  650. // 'content' property's value is still inserted).
  651. // - https://www.w3.org/TR/CSS21/generate.html#quotes-insert
  652. // (This is missing from the CONTENT-3 spec.)
  653. if (quote_nesting_level > 0)
  654. builder.append(get_quote_string(false, --quote_nesting_level));
  655. break;
  656. case Keyword::NoOpenQuote:
  657. quote_nesting_level++;
  658. break;
  659. case Keyword::NoCloseQuote:
  660. // NOTE: See CloseQuote
  661. if (quote_nesting_level > 0)
  662. quote_nesting_level--;
  663. break;
  664. default:
  665. dbgln("`{}` is not supported in `content` (yet?)", item->to_string());
  666. break;
  667. }
  668. } else if (item->is_counter()) {
  669. builder.append(item->as_counter().resolve(element));
  670. } else {
  671. // TODO: Implement images, and other things.
  672. dbgln("`{}` is not supported in `content` (yet?)", item->to_string());
  673. }
  674. }
  675. content_data.type = ContentData::Type::String;
  676. content_data.data = MUST(builder.to_string());
  677. if (content_style_value.has_alt_text()) {
  678. StringBuilder alt_text_builder;
  679. for (auto const& item : content_style_value.alt_text()->values()) {
  680. if (item->is_string()) {
  681. alt_text_builder.append(item->as_string().string_value());
  682. } else if (item->is_counter()) {
  683. alt_text_builder.append(item->as_counter().resolve(element));
  684. } else {
  685. dbgln("`{}` is not supported in `content` alt-text (yet?)", item->to_string());
  686. }
  687. }
  688. content_data.alt_text = MUST(alt_text_builder.to_string());
  689. }
  690. return { content_data, quote_nesting_level };
  691. }
  692. switch (value->to_keyword()) {
  693. case Keyword::None:
  694. return { { ContentData::Type::None }, quote_nesting_level };
  695. case Keyword::Normal:
  696. return { { ContentData::Type::Normal }, quote_nesting_level };
  697. default:
  698. break;
  699. }
  700. return { {}, quote_nesting_level };
  701. }
  702. Optional<CSS::ContentVisibility> StyleProperties::content_visibility() const
  703. {
  704. auto value = property(CSS::PropertyID::ContentVisibility);
  705. return keyword_to_content_visibility(value->to_keyword());
  706. }
  707. Optional<CSS::Cursor> StyleProperties::cursor() const
  708. {
  709. auto value = property(CSS::PropertyID::Cursor);
  710. return keyword_to_cursor(value->to_keyword());
  711. }
  712. Optional<CSS::Visibility> StyleProperties::visibility() const
  713. {
  714. auto value = property(CSS::PropertyID::Visibility);
  715. if (!value->is_keyword())
  716. return {};
  717. return keyword_to_visibility(value->to_keyword());
  718. }
  719. Display StyleProperties::display() const
  720. {
  721. auto value = property(PropertyID::Display);
  722. if (value->is_display()) {
  723. return value->as_display().display();
  724. }
  725. return Display::from_short(Display::Short::Inline);
  726. }
  727. Vector<CSS::TextDecorationLine> StyleProperties::text_decoration_line() const
  728. {
  729. auto value = property(CSS::PropertyID::TextDecorationLine);
  730. if (value->is_value_list()) {
  731. Vector<CSS::TextDecorationLine> lines;
  732. auto& values = value->as_value_list().values();
  733. for (auto const& item : values) {
  734. lines.append(keyword_to_text_decoration_line(item->to_keyword()).value());
  735. }
  736. return lines;
  737. }
  738. if (value->is_keyword() && value->to_keyword() == Keyword::None)
  739. return {};
  740. dbgln("FIXME: Unsupported value for text-decoration-line: {}", value->to_string());
  741. return {};
  742. }
  743. Optional<CSS::TextDecorationStyle> StyleProperties::text_decoration_style() const
  744. {
  745. auto value = property(CSS::PropertyID::TextDecorationStyle);
  746. return keyword_to_text_decoration_style(value->to_keyword());
  747. }
  748. Optional<CSS::TextTransform> StyleProperties::text_transform() const
  749. {
  750. auto value = property(CSS::PropertyID::TextTransform);
  751. return keyword_to_text_transform(value->to_keyword());
  752. }
  753. Optional<CSS::ListStyleType> StyleProperties::list_style_type() const
  754. {
  755. auto value = property(CSS::PropertyID::ListStyleType);
  756. return keyword_to_list_style_type(value->to_keyword());
  757. }
  758. Optional<CSS::ListStylePosition> StyleProperties::list_style_position() const
  759. {
  760. auto value = property(CSS::PropertyID::ListStylePosition);
  761. return keyword_to_list_style_position(value->to_keyword());
  762. }
  763. Optional<CSS::Overflow> StyleProperties::overflow_x() const
  764. {
  765. return overflow(CSS::PropertyID::OverflowX);
  766. }
  767. Optional<CSS::Overflow> StyleProperties::overflow_y() const
  768. {
  769. return overflow(CSS::PropertyID::OverflowY);
  770. }
  771. Optional<CSS::Overflow> StyleProperties::overflow(CSS::PropertyID property_id) const
  772. {
  773. auto value = property(property_id);
  774. return keyword_to_overflow(value->to_keyword());
  775. }
  776. Vector<ShadowData> StyleProperties::shadow(PropertyID property_id, Layout::Node const& layout_node) const
  777. {
  778. auto value = property(property_id);
  779. auto resolve_to_length = [&layout_node](NonnullRefPtr<CSSStyleValue const> const& value) -> Optional<Length> {
  780. if (value->is_length())
  781. return value->as_length().length();
  782. if (value->is_math())
  783. return value->as_math().resolve_length(layout_node);
  784. return {};
  785. };
  786. auto make_shadow_data = [resolve_to_length, &layout_node](ShadowStyleValue const& value) -> Optional<ShadowData> {
  787. auto maybe_offset_x = resolve_to_length(value.offset_x());
  788. if (!maybe_offset_x.has_value())
  789. return {};
  790. auto maybe_offset_y = resolve_to_length(value.offset_y());
  791. if (!maybe_offset_y.has_value())
  792. return {};
  793. auto maybe_blur_radius = resolve_to_length(value.blur_radius());
  794. if (!maybe_blur_radius.has_value())
  795. return {};
  796. auto maybe_spread_distance = resolve_to_length(value.spread_distance());
  797. if (!maybe_spread_distance.has_value())
  798. return {};
  799. return ShadowData {
  800. value.color()->to_color(verify_cast<Layout::NodeWithStyle>(layout_node)),
  801. maybe_offset_x.release_value(),
  802. maybe_offset_y.release_value(),
  803. maybe_blur_radius.release_value(),
  804. maybe_spread_distance.release_value(),
  805. value.placement()
  806. };
  807. };
  808. if (value->is_value_list()) {
  809. auto const& value_list = value->as_value_list();
  810. Vector<ShadowData> shadow_data;
  811. shadow_data.ensure_capacity(value_list.size());
  812. for (auto const& layer_value : value_list.values()) {
  813. auto maybe_shadow_data = make_shadow_data(layer_value->as_shadow());
  814. if (!maybe_shadow_data.has_value())
  815. return {};
  816. shadow_data.append(maybe_shadow_data.release_value());
  817. }
  818. return shadow_data;
  819. }
  820. if (value->is_shadow()) {
  821. auto maybe_shadow_data = make_shadow_data(value->as_shadow());
  822. if (!maybe_shadow_data.has_value())
  823. return {};
  824. return { maybe_shadow_data.release_value() };
  825. }
  826. return {};
  827. }
  828. Vector<ShadowData> StyleProperties::box_shadow(Layout::Node const& layout_node) const
  829. {
  830. return shadow(PropertyID::BoxShadow, layout_node);
  831. }
  832. Vector<ShadowData> StyleProperties::text_shadow(Layout::Node const& layout_node) const
  833. {
  834. return shadow(PropertyID::TextShadow, layout_node);
  835. }
  836. Optional<CSS::BoxSizing> StyleProperties::box_sizing() const
  837. {
  838. auto value = property(CSS::PropertyID::BoxSizing);
  839. return keyword_to_box_sizing(value->to_keyword());
  840. }
  841. Variant<CSS::VerticalAlign, CSS::LengthPercentage> StyleProperties::vertical_align() const
  842. {
  843. auto value = property(CSS::PropertyID::VerticalAlign);
  844. if (value->is_keyword())
  845. return keyword_to_vertical_align(value->to_keyword()).release_value();
  846. if (value->is_length())
  847. return CSS::LengthPercentage(value->as_length().length());
  848. if (value->is_percentage())
  849. return CSS::LengthPercentage(value->as_percentage().percentage());
  850. if (value->is_math())
  851. return LengthPercentage { const_cast<CSSMathValue&>(value->as_math()) };
  852. VERIFY_NOT_REACHED();
  853. }
  854. Optional<CSS::FontVariant> StyleProperties::font_variant() const
  855. {
  856. auto value = property(CSS::PropertyID::FontVariant);
  857. return keyword_to_font_variant(value->to_keyword());
  858. }
  859. CSS::GridTrackSizeList StyleProperties::grid_auto_columns() const
  860. {
  861. auto value = property(CSS::PropertyID::GridAutoColumns);
  862. return value->as_grid_track_size_list().grid_track_size_list();
  863. }
  864. CSS::GridTrackSizeList StyleProperties::grid_auto_rows() const
  865. {
  866. auto value = property(CSS::PropertyID::GridAutoRows);
  867. return value->as_grid_track_size_list().grid_track_size_list();
  868. }
  869. CSS::GridTrackSizeList StyleProperties::grid_template_columns() const
  870. {
  871. auto value = property(CSS::PropertyID::GridTemplateColumns);
  872. return value->as_grid_track_size_list().grid_track_size_list();
  873. }
  874. CSS::GridTrackSizeList StyleProperties::grid_template_rows() const
  875. {
  876. auto value = property(CSS::PropertyID::GridTemplateRows);
  877. return value->as_grid_track_size_list().grid_track_size_list();
  878. }
  879. CSS::GridAutoFlow StyleProperties::grid_auto_flow() const
  880. {
  881. auto value = property(CSS::PropertyID::GridAutoFlow);
  882. if (!value->is_grid_auto_flow())
  883. return CSS::GridAutoFlow {};
  884. auto& grid_auto_flow_value = value->as_grid_auto_flow();
  885. return CSS::GridAutoFlow { .row = grid_auto_flow_value.is_row(), .dense = grid_auto_flow_value.is_dense() };
  886. }
  887. CSS::GridTrackPlacement StyleProperties::grid_column_end() const
  888. {
  889. auto value = property(CSS::PropertyID::GridColumnEnd);
  890. return value->as_grid_track_placement().grid_track_placement();
  891. }
  892. CSS::GridTrackPlacement StyleProperties::grid_column_start() const
  893. {
  894. auto value = property(CSS::PropertyID::GridColumnStart);
  895. return value->as_grid_track_placement().grid_track_placement();
  896. }
  897. CSS::GridTrackPlacement StyleProperties::grid_row_end() const
  898. {
  899. auto value = property(CSS::PropertyID::GridRowEnd);
  900. return value->as_grid_track_placement().grid_track_placement();
  901. }
  902. CSS::GridTrackPlacement StyleProperties::grid_row_start() const
  903. {
  904. auto value = property(CSS::PropertyID::GridRowStart);
  905. return value->as_grid_track_placement().grid_track_placement();
  906. }
  907. Optional<CSS::BorderCollapse> StyleProperties::border_collapse() const
  908. {
  909. auto value = property(CSS::PropertyID::BorderCollapse);
  910. return keyword_to_border_collapse(value->to_keyword());
  911. }
  912. Vector<Vector<String>> StyleProperties::grid_template_areas() const
  913. {
  914. auto value = property(CSS::PropertyID::GridTemplateAreas);
  915. return value->as_grid_template_area().grid_template_area();
  916. }
  917. Optional<CSS::ObjectFit> StyleProperties::object_fit() const
  918. {
  919. auto value = property(CSS::PropertyID::ObjectFit);
  920. return keyword_to_object_fit(value->to_keyword());
  921. }
  922. CSS::ObjectPosition StyleProperties::object_position() const
  923. {
  924. auto value = property(CSS::PropertyID::ObjectPosition);
  925. auto const& position = value->as_position();
  926. CSS::ObjectPosition object_position;
  927. auto const& edge_x = position.edge_x();
  928. auto const& edge_y = position.edge_y();
  929. if (edge_x->is_edge()) {
  930. auto const& edge = edge_x->as_edge();
  931. object_position.edge_x = edge.edge();
  932. object_position.offset_x = edge.offset();
  933. }
  934. if (edge_y->is_edge()) {
  935. auto const& edge = edge_y->as_edge();
  936. object_position.edge_y = edge.edge();
  937. object_position.offset_y = edge.offset();
  938. }
  939. return object_position;
  940. }
  941. Optional<CSS::TableLayout> StyleProperties::table_layout() const
  942. {
  943. auto value = property(CSS::PropertyID::TableLayout);
  944. return keyword_to_table_layout(value->to_keyword());
  945. }
  946. Optional<CSS::Direction> StyleProperties::direction() const
  947. {
  948. auto value = property(CSS::PropertyID::Direction);
  949. return keyword_to_direction(value->to_keyword());
  950. }
  951. Optional<CSS::MaskType> StyleProperties::mask_type() const
  952. {
  953. auto value = property(CSS::PropertyID::MaskType);
  954. return keyword_to_mask_type(value->to_keyword());
  955. }
  956. Color StyleProperties::stop_color() const
  957. {
  958. auto value = property(CSS::PropertyID::StopColor);
  959. if (value->is_keyword()) {
  960. // Workaround lack of layout node to resolve current color.
  961. auto& keyword = value->as_keyword();
  962. if (keyword.keyword() == CSS::Keyword::Currentcolor)
  963. value = property(CSS::PropertyID::Color);
  964. }
  965. if (value->has_color()) {
  966. // FIXME: This is used by the SVGStopElement, which does not participate in layout,
  967. // so can't pass a layout node (so can't resolve some colors, e.g. palette ones)
  968. return value->to_color({});
  969. }
  970. return Color::Black;
  971. }
  972. void StyleProperties::set_math_depth(int math_depth)
  973. {
  974. m_data->m_math_depth = math_depth;
  975. // Make our children inherit our computed value, not our specified value.
  976. set_property(PropertyID::MathDepth, MathDepthStyleValue::create_integer(IntegerStyleValue::create(math_depth)));
  977. }
  978. QuotesData StyleProperties::quotes() const
  979. {
  980. auto value = property(CSS::PropertyID::Quotes);
  981. if (value->is_keyword()) {
  982. switch (value->to_keyword()) {
  983. case Keyword::Auto:
  984. return QuotesData { .type = QuotesData::Type::Auto };
  985. case Keyword::None:
  986. return QuotesData { .type = QuotesData::Type::None };
  987. default:
  988. break;
  989. }
  990. }
  991. if (value->is_value_list()) {
  992. auto& value_list = value->as_value_list();
  993. QuotesData quotes_data { .type = QuotesData::Type::Specified };
  994. VERIFY(value_list.size() % 2 == 0);
  995. for (auto i = 0u; i < value_list.size(); i += 2) {
  996. quotes_data.strings.empend(
  997. value_list.value_at(i, false)->as_string().string_value(),
  998. value_list.value_at(i + 1, false)->as_string().string_value());
  999. }
  1000. return quotes_data;
  1001. }
  1002. return InitialValues::quotes();
  1003. }
  1004. Vector<CounterData> StyleProperties::counter_data(PropertyID property_id) const
  1005. {
  1006. auto value = property(property_id);
  1007. if (value->is_counter_definitions()) {
  1008. auto& counter_definitions = value->as_counter_definitions().counter_definitions();
  1009. Vector<CounterData> result;
  1010. for (auto& counter : counter_definitions) {
  1011. CounterData data {
  1012. .name = counter.name,
  1013. .is_reversed = counter.is_reversed,
  1014. .value = {},
  1015. };
  1016. if (counter.value) {
  1017. if (counter.value->is_integer()) {
  1018. data.value = AK::clamp_to<i32>(counter.value->as_integer().integer());
  1019. } else if (counter.value->is_math()) {
  1020. auto maybe_int = counter.value->as_math().resolve_integer();
  1021. if (maybe_int.has_value())
  1022. data.value = AK::clamp_to<i32>(*maybe_int);
  1023. } else {
  1024. dbgln("Unimplemented type for {} integer value: '{}'", string_from_property_id(property_id), counter.value->to_string());
  1025. }
  1026. }
  1027. result.append(move(data));
  1028. }
  1029. return result;
  1030. }
  1031. if (value->to_keyword() == Keyword::None)
  1032. return {};
  1033. dbgln("Unhandled type for {} value: '{}'", string_from_property_id(property_id), value->to_string());
  1034. return {};
  1035. }
  1036. Optional<CSS::ScrollbarWidth> StyleProperties::scrollbar_width() const
  1037. {
  1038. auto value = property(CSS::PropertyID::ScrollbarWidth);
  1039. return keyword_to_scrollbar_width(value->to_keyword());
  1040. }
  1041. }