ResolvedCSSStyleDeclaration.cpp 23 KB

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