StyleProperties.cpp 42 KB

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