ResolvedCSSStyleDeclaration.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <AK/NonnullRefPtr.h>
  8. #include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
  9. #include <LibWeb/CSS/StyleComputer.h>
  10. #include <LibWeb/DOM/Document.h>
  11. #include <LibWeb/DOM/Element.h>
  12. namespace Web::CSS {
  13. ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element)
  14. : m_element(element)
  15. {
  16. }
  17. ResolvedCSSStyleDeclaration::~ResolvedCSSStyleDeclaration()
  18. {
  19. }
  20. size_t ResolvedCSSStyleDeclaration::length() const
  21. {
  22. return 0;
  23. }
  24. String ResolvedCSSStyleDeclaration::item(size_t index) const
  25. {
  26. (void)index;
  27. return {};
  28. }
  29. static CSS::ValueID to_css_value_id(CSS::Display value)
  30. {
  31. switch (value) {
  32. case CSS::Display::None:
  33. return CSS::ValueID::None;
  34. case CSS::Display::Block:
  35. return CSS::ValueID::Block;
  36. case CSS::Display::Inline:
  37. return CSS::ValueID::Inline;
  38. case CSS::Display::InlineBlock:
  39. return CSS::ValueID::InlineBlock;
  40. case CSS::Display::ListItem:
  41. return CSS::ValueID::ListItem;
  42. case CSS::Display::Table:
  43. return CSS::ValueID::Table;
  44. case CSS::Display::TableRow:
  45. return CSS::ValueID::TableRow;
  46. case CSS::Display::TableCell:
  47. return CSS::ValueID::TableCell;
  48. case CSS::Display::TableHeaderGroup:
  49. return CSS::ValueID::TableHeaderGroup;
  50. case CSS::Display::TableRowGroup:
  51. return CSS::ValueID::TableRowGroup;
  52. case CSS::Display::TableFooterGroup:
  53. return CSS::ValueID::TableFooterGroup;
  54. case CSS::Display::TableColumn:
  55. return CSS::ValueID::TableColumn;
  56. case CSS::Display::TableColumnGroup:
  57. return CSS::ValueID::TableColumnGroup;
  58. case CSS::Display::TableCaption:
  59. return CSS::ValueID::TableCaption;
  60. case CSS::Display::Flex:
  61. return CSS::ValueID::Flex;
  62. }
  63. VERIFY_NOT_REACHED();
  64. }
  65. static CSS::ValueID to_css_value_id(CSS::Float value)
  66. {
  67. switch (value) {
  68. case Float::None:
  69. return CSS::ValueID::None;
  70. case Float::Left:
  71. return CSS::ValueID::Left;
  72. case Float::Right:
  73. return CSS::ValueID::Right;
  74. }
  75. VERIFY_NOT_REACHED();
  76. }
  77. static CSS::ValueID to_css_value_id(CSS::Clear value)
  78. {
  79. switch (value) {
  80. case Clear::None:
  81. return CSS::ValueID::None;
  82. case Clear::Left:
  83. return CSS::ValueID::Left;
  84. case Clear::Right:
  85. return CSS::ValueID::Right;
  86. case Clear::Both:
  87. return CSS::ValueID::Both;
  88. }
  89. VERIFY_NOT_REACHED();
  90. }
  91. static CSS::ValueID to_css_value_id(CSS::TextDecorationLine value)
  92. {
  93. switch (value) {
  94. case TextDecorationLine::None:
  95. return CSS::ValueID::None;
  96. case TextDecorationLine::Underline:
  97. return CSS::ValueID::Underline;
  98. case TextDecorationLine::Overline:
  99. return CSS::ValueID::Overline;
  100. case TextDecorationLine::LineThrough:
  101. return CSS::ValueID::LineThrough;
  102. case TextDecorationLine::Blink:
  103. return CSS::ValueID::Blink;
  104. }
  105. VERIFY_NOT_REACHED();
  106. }
  107. static CSS::ValueID to_css_value_id(CSS::Cursor value)
  108. {
  109. switch (value) {
  110. case Cursor::Auto:
  111. return CSS::ValueID::Auto;
  112. case Cursor::Default:
  113. return CSS::ValueID::Default;
  114. case Cursor::None:
  115. return CSS::ValueID::None;
  116. case Cursor::ContextMenu:
  117. return CSS::ValueID::ContextMenu;
  118. case Cursor::Help:
  119. return CSS::ValueID::Help;
  120. case Cursor::Pointer:
  121. return CSS::ValueID::Pointer;
  122. case Cursor::Progress:
  123. return CSS::ValueID::Progress;
  124. case Cursor::Wait:
  125. return CSS::ValueID::Wait;
  126. case Cursor::Cell:
  127. return CSS::ValueID::Cell;
  128. case Cursor::Crosshair:
  129. return CSS::ValueID::Crosshair;
  130. case Cursor::Text:
  131. return CSS::ValueID::Text;
  132. case Cursor::VerticalText:
  133. return CSS::ValueID::VerticalText;
  134. case Cursor::Alias:
  135. return CSS::ValueID::Alias;
  136. case Cursor::Copy:
  137. return CSS::ValueID::Copy;
  138. case Cursor::Move:
  139. return CSS::ValueID::Move;
  140. case Cursor::NoDrop:
  141. return CSS::ValueID::NoDrop;
  142. case Cursor::NotAllowed:
  143. return CSS::ValueID::NotAllowed;
  144. case Cursor::Grab:
  145. return CSS::ValueID::Grab;
  146. case Cursor::Grabbing:
  147. return CSS::ValueID::Grabbing;
  148. case Cursor::EResize:
  149. return CSS::ValueID::EResize;
  150. case Cursor::NResize:
  151. return CSS::ValueID::NResize;
  152. case Cursor::NeResize:
  153. return CSS::ValueID::NeResize;
  154. case Cursor::NwResize:
  155. return CSS::ValueID::NwResize;
  156. case Cursor::SResize:
  157. return CSS::ValueID::SResize;
  158. case Cursor::SeResize:
  159. return CSS::ValueID::SeResize;
  160. case Cursor::SwResize:
  161. return CSS::ValueID::SwResize;
  162. case Cursor::WResize:
  163. return CSS::ValueID::WResize;
  164. case Cursor::EwResize:
  165. return CSS::ValueID::EwResize;
  166. case Cursor::NsResize:
  167. return CSS::ValueID::NsResize;
  168. case Cursor::NeswResize:
  169. return CSS::ValueID::NeswResize;
  170. case Cursor::NwseResize:
  171. return CSS::ValueID::NwseResize;
  172. case Cursor::ColResize:
  173. return CSS::ValueID::ColResize;
  174. case Cursor::RowResize:
  175. return CSS::ValueID::RowResize;
  176. case Cursor::AllScroll:
  177. return CSS::ValueID::AllScroll;
  178. case Cursor::ZoomIn:
  179. return CSS::ValueID::ZoomIn;
  180. case Cursor::ZoomOut:
  181. return CSS::ValueID::ZoomOut;
  182. }
  183. VERIFY_NOT_REACHED();
  184. }
  185. static CSS::ValueID to_css_value_id(CSS::TextAlign value)
  186. {
  187. switch (value) {
  188. case TextAlign::Left:
  189. return CSS::ValueID::Left;
  190. case TextAlign::Center:
  191. return CSS::ValueID::Center;
  192. case TextAlign::Right:
  193. return CSS::ValueID::Right;
  194. case TextAlign::Justify:
  195. return CSS::ValueID::Justify;
  196. case TextAlign::LibwebCenter:
  197. return CSS::ValueID::LibwebCenter;
  198. }
  199. VERIFY_NOT_REACHED();
  200. }
  201. static CSS::ValueID to_css_value_id(CSS::TextTransform value)
  202. {
  203. switch (value) {
  204. case TextTransform::None:
  205. return CSS::ValueID::None;
  206. case TextTransform::Capitalize:
  207. return CSS::ValueID::Capitalize;
  208. case TextTransform::Uppercase:
  209. return CSS::ValueID::Uppercase;
  210. case TextTransform::Lowercase:
  211. return CSS::ValueID::Lowercase;
  212. case TextTransform::FullWidth:
  213. return CSS::ValueID::FullWidth;
  214. case TextTransform::FullSizeKana:
  215. return CSS::ValueID::FullSizeKana;
  216. }
  217. VERIFY_NOT_REACHED();
  218. }
  219. static CSS::ValueID to_css_value_id(CSS::Position value)
  220. {
  221. switch (value) {
  222. case Position::Static:
  223. return CSS::ValueID::Static;
  224. case Position::Relative:
  225. return CSS::ValueID::Relative;
  226. case Position::Absolute:
  227. return CSS::ValueID::Absolute;
  228. case Position::Fixed:
  229. return CSS::ValueID::Fixed;
  230. case Position::Sticky:
  231. return CSS::ValueID::Sticky;
  232. }
  233. VERIFY_NOT_REACHED();
  234. }
  235. static CSS::ValueID to_css_value_id(CSS::WhiteSpace value)
  236. {
  237. switch (value) {
  238. case WhiteSpace::Normal:
  239. return CSS::ValueID::Normal;
  240. case WhiteSpace::Pre:
  241. return CSS::ValueID::Pre;
  242. case WhiteSpace::Nowrap:
  243. return CSS::ValueID::Nowrap;
  244. case WhiteSpace::PreLine:
  245. return CSS::ValueID::PreLine;
  246. case WhiteSpace::PreWrap:
  247. return CSS::ValueID::PreWrap;
  248. }
  249. VERIFY_NOT_REACHED();
  250. }
  251. static CSS::ValueID to_css_value_id(CSS::FlexDirection value)
  252. {
  253. switch (value) {
  254. case FlexDirection::Row:
  255. return CSS::ValueID::Row;
  256. case FlexDirection::RowReverse:
  257. return CSS::ValueID::RowReverse;
  258. case FlexDirection::Column:
  259. return CSS::ValueID::Column;
  260. case FlexDirection::ColumnReverse:
  261. return CSS::ValueID::ColumnReverse;
  262. }
  263. VERIFY_NOT_REACHED();
  264. }
  265. static CSS::ValueID to_css_value_id(CSS::FlexWrap value)
  266. {
  267. switch (value) {
  268. case FlexWrap::Nowrap:
  269. return CSS::ValueID::Nowrap;
  270. case FlexWrap::Wrap:
  271. return CSS::ValueID::Wrap;
  272. case FlexWrap::WrapReverse:
  273. return CSS::ValueID::WrapReverse;
  274. }
  275. VERIFY_NOT_REACHED();
  276. }
  277. static CSS::ValueID to_css_value_id(CSS::JustifyContent value)
  278. {
  279. switch (value) {
  280. case JustifyContent::FlexStart:
  281. return CSS::ValueID::FlexStart;
  282. case JustifyContent::FlexEnd:
  283. return CSS::ValueID::FlexEnd;
  284. case JustifyContent::Center:
  285. return CSS::ValueID::Center;
  286. case JustifyContent::SpaceBetween:
  287. return CSS::ValueID::SpaceBetween;
  288. case JustifyContent::SpaceAround:
  289. return CSS::ValueID::SpaceAround;
  290. }
  291. VERIFY_NOT_REACHED();
  292. }
  293. static CSS::ValueID to_css_value_id(CSS::Overflow value)
  294. {
  295. switch (value) {
  296. case Overflow::Auto:
  297. return CSS::ValueID::Auto;
  298. case Overflow::Clip:
  299. return CSS::ValueID::Clip;
  300. case Overflow::Hidden:
  301. return CSS::ValueID::Hidden;
  302. case Overflow::Scroll:
  303. return CSS::ValueID::Scroll;
  304. case Overflow::Visible:
  305. return CSS::ValueID::Visible;
  306. }
  307. VERIFY_NOT_REACHED();
  308. }
  309. static CSS::ValueID to_css_value_id(CSS::Repeat value)
  310. {
  311. switch (value) {
  312. case Repeat::NoRepeat:
  313. return CSS::ValueID::NoRepeat;
  314. case Repeat::Repeat:
  315. return CSS::ValueID::Repeat;
  316. case Repeat::Round:
  317. return CSS::ValueID::Round;
  318. case Repeat::Space:
  319. return CSS::ValueID::Space;
  320. }
  321. VERIFY_NOT_REACHED();
  322. }
  323. static CSS::ValueID to_css_value_id(CSS::ListStyleType value)
  324. {
  325. switch (value) {
  326. case ListStyleType::None:
  327. return CSS::ValueID::None;
  328. case ListStyleType::Disc:
  329. return CSS::ValueID::Disc;
  330. case ListStyleType::Circle:
  331. return CSS::ValueID::Circle;
  332. case ListStyleType::Square:
  333. return CSS::ValueID::Square;
  334. case ListStyleType::Decimal:
  335. return CSS::ValueID::Decimal;
  336. case ListStyleType::DecimalLeadingZero:
  337. return CSS::ValueID::DecimalLeadingZero;
  338. case ListStyleType::LowerAlpha:
  339. return CSS::ValueID::LowerAlpha;
  340. case ListStyleType::LowerLatin:
  341. return CSS::ValueID::LowerLatin;
  342. case ListStyleType::LowerRoman:
  343. return CSS::ValueID::LowerRoman;
  344. case ListStyleType::UpperAlpha:
  345. return CSS::ValueID::UpperAlpha;
  346. case ListStyleType::UpperLatin:
  347. return CSS::ValueID::UpperLatin;
  348. case ListStyleType::UpperRoman:
  349. return CSS::ValueID::UpperRoman;
  350. }
  351. VERIFY_NOT_REACHED();
  352. }
  353. static NonnullRefPtr<StyleValue> value_or_default(Optional<StyleProperty> property, NonnullRefPtr<StyleValue> default_style)
  354. {
  355. if (property.has_value())
  356. return property.value().value;
  357. return default_style;
  358. }
  359. RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const
  360. {
  361. switch (property_id) {
  362. case CSS::PropertyID::Float:
  363. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().float_()));
  364. case CSS::PropertyID::Clear:
  365. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().clear()));
  366. case CSS::PropertyID::Cursor:
  367. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().cursor()));
  368. case CSS::PropertyID::Display:
  369. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().display()));
  370. case CSS::PropertyID::ZIndex: {
  371. auto maybe_z_index = layout_node.computed_values().z_index();
  372. if (!maybe_z_index.has_value())
  373. return {};
  374. return NumericStyleValue::create(maybe_z_index.release_value());
  375. }
  376. case CSS::PropertyID::TextAlign:
  377. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_align()));
  378. case CSS::PropertyID::TextDecorationLine:
  379. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_decoration_line()));
  380. case CSS::PropertyID::TextTransform:
  381. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_transform()));
  382. case CSS::PropertyID::Position:
  383. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().position()));
  384. case CSS::PropertyID::WhiteSpace:
  385. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().white_space()));
  386. case CSS::PropertyID::FlexDirection:
  387. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_direction()));
  388. case CSS::PropertyID::FlexWrap:
  389. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_wrap()));
  390. case CSS::PropertyID::FlexBasis: {
  391. switch (layout_node.computed_values().flex_basis().type) {
  392. case FlexBasis::Content:
  393. return IdentifierStyleValue::create(CSS::ValueID::Content);
  394. case FlexBasis::Length:
  395. return LengthStyleValue::create(layout_node.computed_values().flex_basis().length);
  396. case FlexBasis::Auto:
  397. return IdentifierStyleValue::create(CSS::ValueID::Auto);
  398. default:
  399. VERIFY_NOT_REACHED();
  400. }
  401. break;
  402. case CSS::PropertyID::FlexGrow: {
  403. auto maybe_grow_factor = layout_node.computed_values().flex_grow_factor();
  404. if (!maybe_grow_factor.has_value())
  405. return {};
  406. return NumericStyleValue::create(maybe_grow_factor.release_value());
  407. }
  408. case CSS::PropertyID::FlexShrink: {
  409. auto maybe_shrink_factor = layout_node.computed_values().flex_shrink_factor();
  410. if (!maybe_shrink_factor.has_value())
  411. return {};
  412. return NumericStyleValue::create(maybe_shrink_factor.release_value());
  413. }
  414. case CSS::PropertyID::Opacity: {
  415. auto maybe_opacity = layout_node.computed_values().opacity();
  416. if (!maybe_opacity.has_value())
  417. return {};
  418. return NumericStyleValue::create(maybe_opacity.release_value());
  419. }
  420. case CSS::PropertyID::JustifyContent:
  421. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().justify_content()));
  422. case CSS::PropertyID::BoxShadow: {
  423. auto maybe_box_shadow = layout_node.computed_values().box_shadow();
  424. if (!maybe_box_shadow.has_value())
  425. return {};
  426. auto box_shadow_data = maybe_box_shadow.release_value();
  427. return BoxShadowStyleValue::create(box_shadow_data.offset_x, box_shadow_data.offset_y, box_shadow_data.blur_radius, box_shadow_data.color);
  428. }
  429. case CSS::PropertyID::Width:
  430. return LengthStyleValue::create(layout_node.computed_values().width());
  431. case CSS::PropertyID::MinWidth:
  432. if (layout_node.computed_values().min_width().is_undefined())
  433. return IdentifierStyleValue::create(CSS::ValueID::None);
  434. return LengthStyleValue::create(layout_node.computed_values().min_width());
  435. case CSS::PropertyID::MaxWidth:
  436. if (layout_node.computed_values().max_width().is_undefined())
  437. return IdentifierStyleValue::create(CSS::ValueID::None);
  438. return LengthStyleValue::create(layout_node.computed_values().max_width());
  439. case CSS::PropertyID::Height:
  440. return LengthStyleValue::create(layout_node.computed_values().height());
  441. case CSS::PropertyID::MinHeight:
  442. if (layout_node.computed_values().min_height().is_undefined())
  443. return IdentifierStyleValue::create(CSS::ValueID::None);
  444. return LengthStyleValue::create(layout_node.computed_values().min_height());
  445. case CSS::PropertyID::MaxHeight:
  446. if (layout_node.computed_values().max_height().is_undefined())
  447. return IdentifierStyleValue::create(CSS::ValueID::None);
  448. return LengthStyleValue::create(layout_node.computed_values().max_height());
  449. case CSS::PropertyID::MarginTop:
  450. return LengthStyleValue::create(layout_node.computed_values().margin().top);
  451. case CSS::PropertyID::MarginRight:
  452. return LengthStyleValue::create(layout_node.computed_values().margin().right);
  453. case CSS::PropertyID::MarginBottom:
  454. return LengthStyleValue::create(layout_node.computed_values().margin().bottom);
  455. case CSS::PropertyID::MarginLeft:
  456. return LengthStyleValue::create(layout_node.computed_values().margin().left);
  457. case CSS::PropertyID::PaddingTop:
  458. return LengthStyleValue::create(layout_node.computed_values().padding().top);
  459. case CSS::PropertyID::PaddingRight:
  460. return LengthStyleValue::create(layout_node.computed_values().padding().right);
  461. case CSS::PropertyID::PaddingBottom:
  462. return LengthStyleValue::create(layout_node.computed_values().padding().bottom);
  463. case CSS::PropertyID::PaddingLeft:
  464. return LengthStyleValue::create(layout_node.computed_values().padding().left);
  465. case CSS::PropertyID::BorderRadius: {
  466. auto maybe_top_left_radius = property(CSS::PropertyID::BorderTopLeftRadius);
  467. auto maybe_top_right_radius = property(CSS::PropertyID::BorderTopRightRadius);
  468. auto maybe_bottom_left_radius = property(CSS::PropertyID::BorderBottomLeftRadius);
  469. auto maybe_bottom_right_radius = property(CSS::PropertyID::BorderBottomRightRadius);
  470. RefPtr<BorderRadiusStyleValue> top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius;
  471. if (maybe_top_left_radius.has_value()) {
  472. VERIFY(maybe_top_left_radius.value().value->is_border_radius());
  473. top_left_radius = maybe_top_left_radius.value().value->as_border_radius();
  474. }
  475. if (maybe_top_right_radius.has_value()) {
  476. VERIFY(maybe_top_right_radius.value().value->is_border_radius());
  477. top_right_radius = maybe_top_right_radius.value().value->as_border_radius();
  478. }
  479. if (maybe_bottom_left_radius.has_value()) {
  480. VERIFY(maybe_bottom_left_radius.value().value->is_border_radius());
  481. bottom_left_radius = maybe_bottom_left_radius.value().value->as_border_radius();
  482. }
  483. if (maybe_bottom_right_radius.has_value()) {
  484. VERIFY(maybe_bottom_right_radius.value().value->is_border_radius());
  485. bottom_right_radius = maybe_bottom_right_radius.value().value->as_border_radius();
  486. }
  487. return CombinedBorderRadiusStyleValue::create(top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull());
  488. }
  489. // FIXME: The two radius components are not yet stored, as we currently don't actually render them.
  490. case CSS::PropertyID::BorderBottomLeftRadius:
  491. return BorderRadiusStyleValue::create(layout_node.computed_values().border_bottom_left_radius(), layout_node.computed_values().border_bottom_left_radius());
  492. case CSS::PropertyID::BorderBottomRightRadius:
  493. return BorderRadiusStyleValue::create(layout_node.computed_values().border_bottom_right_radius(), layout_node.computed_values().border_bottom_right_radius());
  494. case CSS::PropertyID::BorderTopLeftRadius:
  495. return BorderRadiusStyleValue::create(layout_node.computed_values().border_top_left_radius(), layout_node.computed_values().border_top_left_radius());
  496. case CSS::PropertyID::BorderTopRightRadius:
  497. return BorderRadiusStyleValue::create(layout_node.computed_values().border_top_right_radius(), layout_node.computed_values().border_top_right_radius());
  498. case CSS::PropertyID::OverflowX:
  499. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_x()));
  500. case CSS::PropertyID::OverflowY:
  501. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_y()));
  502. case CSS::PropertyID::Color:
  503. return ColorStyleValue::create(layout_node.computed_values().color());
  504. case PropertyID::BackgroundColor:
  505. return ColorStyleValue::create(layout_node.computed_values().background_color());
  506. case CSS::PropertyID::BackgroundRepeatX:
  507. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().background_repeat_x()));
  508. case CSS::PropertyID::BackgroundRepeatY:
  509. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().background_repeat_y()));
  510. case CSS::PropertyID::BackgroundRepeat: {
  511. auto maybe_background_repeat_x = property(CSS::PropertyID::BackgroundRepeatX);
  512. auto maybe_background_repeat_y = property(CSS::PropertyID::BackgroundRepeatY);
  513. return BackgroundRepeatStyleValue::create(value_or_default(maybe_background_repeat_x, IdentifierStyleValue::create(CSS::ValueID::RepeatX)), value_or_default(maybe_background_repeat_y, IdentifierStyleValue::create(CSS::ValueID::RepeatY)));
  514. }
  515. case CSS::PropertyID::Background: {
  516. auto maybe_background_color = property(CSS::PropertyID::BackgroundColor);
  517. auto maybe_background_image = property(CSS::PropertyID::BackgroundImage);
  518. auto maybe_background_repeat_x = property(CSS::PropertyID::BackgroundRepeatX);
  519. auto maybe_background_repeat_y = property(CSS::PropertyID::BackgroundRepeatY);
  520. return BackgroundStyleValue::create(value_or_default(maybe_background_color, InitialStyleValue::the()), value_or_default(maybe_background_image, IdentifierStyleValue::create(CSS::ValueID::None)), value_or_default(maybe_background_repeat_x, IdentifierStyleValue::create(CSS::ValueID::RepeatX)), value_or_default(maybe_background_repeat_y, IdentifierStyleValue::create(CSS::ValueID::RepeatX)));
  521. }
  522. case CSS::PropertyID::ListStyleType:
  523. return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().list_style_type()));
  524. case CSS::PropertyID::Invalid:
  525. return IdentifierStyleValue::create(CSS::ValueID::Invalid);
  526. case CSS::PropertyID::Custom:
  527. dbgln("Computed style for custom properties was requested (?)");
  528. return {};
  529. default:
  530. dbgln("FIXME: Computed style for the '{}' property was requested", string_from_property_id(property_id));
  531. return {};
  532. }
  533. }
  534. }
  535. Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID property_id) const
  536. {
  537. const_cast<DOM::Document&>(m_element->document()).ensure_layout();
  538. if (!m_element->layout_node()) {
  539. auto style = m_element->document().style_computer().compute_style(const_cast<DOM::Element&>(*m_element));
  540. if (auto maybe_property = style->property(property_id); maybe_property.has_value()) {
  541. return StyleProperty {
  542. .property_id = property_id,
  543. .value = maybe_property.release_value(),
  544. };
  545. }
  546. return {};
  547. }
  548. auto& layout_node = *m_element->layout_node();
  549. auto value = style_value_for_property(layout_node, property_id);
  550. if (!value)
  551. return {};
  552. return StyleProperty {
  553. .property_id = property_id,
  554. .value = value.release_nonnull(),
  555. };
  556. }
  557. bool ResolvedCSSStyleDeclaration::set_property(PropertyID, StringView)
  558. {
  559. return false;
  560. }
  561. String ResolvedCSSStyleDeclaration::serialized() const
  562. {
  563. // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
  564. // If the computed flag is set, then return the empty string.
  565. // NOTE: ResolvedCSSStyleDeclaration is something you would only get from window.getComputedStyle(),
  566. // which returns what the spec calls "resolved style". The "computed flag" is always set here.
  567. return String::empty();
  568. }
  569. }