ComputedCSSStyleDeclaration.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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/ComputedCSSStyleDeclaration.h>
  9. #include <LibWeb/CSS/StyleResolver.h>
  10. #include <LibWeb/DOM/Document.h>
  11. #include <LibWeb/DOM/Element.h>
  12. namespace Web::CSS {
  13. ComputedCSSStyleDeclaration::ComputedCSSStyleDeclaration(DOM::Element& element)
  14. : m_element(element)
  15. {
  16. }
  17. ComputedCSSStyleDeclaration::~ComputedCSSStyleDeclaration()
  18. {
  19. }
  20. size_t ComputedCSSStyleDeclaration::length() const
  21. {
  22. return 0;
  23. }
  24. String ComputedCSSStyleDeclaration::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. Optional<StyleProperty> ComputedCSSStyleDeclaration::property(PropertyID property_id) const
  360. {
  361. const_cast<DOM::Document&>(m_element->document()).ensure_layout();
  362. if (!m_element->layout_node()) {
  363. auto style = m_element->document().style_resolver().resolve_style(const_cast<DOM::Element&>(*m_element));
  364. if (auto maybe_property = style->property(property_id); maybe_property.has_value()) {
  365. return StyleProperty {
  366. .property_id = property_id,
  367. .value = maybe_property.release_value(),
  368. };
  369. }
  370. return {};
  371. }
  372. auto& layout_node = *m_element->layout_node();
  373. switch (property_id) {
  374. case CSS::PropertyID::Float:
  375. return StyleProperty {
  376. .property_id = property_id,
  377. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().float_())),
  378. };
  379. case CSS::PropertyID::Clear:
  380. return StyleProperty {
  381. .property_id = property_id,
  382. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().clear())),
  383. };
  384. case CSS::PropertyID::Cursor:
  385. return StyleProperty {
  386. .property_id = property_id,
  387. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().cursor())),
  388. };
  389. case CSS::PropertyID::Display:
  390. return StyleProperty {
  391. .property_id = property_id,
  392. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().display())),
  393. };
  394. case CSS::PropertyID::ZIndex: {
  395. auto maybe_z_index = layout_node.computed_values().z_index();
  396. if (!maybe_z_index.has_value())
  397. return {};
  398. return StyleProperty {
  399. .property_id = property_id,
  400. .value = NumericStyleValue::create(maybe_z_index.release_value()),
  401. };
  402. }
  403. case CSS::PropertyID::TextAlign:
  404. return StyleProperty {
  405. .property_id = property_id,
  406. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_align())),
  407. };
  408. case CSS::PropertyID::TextDecorationLine:
  409. return StyleProperty {
  410. .property_id = property_id,
  411. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_decoration_line())),
  412. };
  413. case CSS::PropertyID::TextTransform:
  414. return StyleProperty {
  415. .property_id = property_id,
  416. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_transform())),
  417. };
  418. case CSS::PropertyID::Position:
  419. return StyleProperty {
  420. .property_id = property_id,
  421. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().position())),
  422. };
  423. case CSS::PropertyID::WhiteSpace:
  424. return StyleProperty {
  425. .property_id = property_id,
  426. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().white_space())),
  427. };
  428. case CSS::PropertyID::FlexDirection:
  429. return StyleProperty {
  430. .property_id = property_id,
  431. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_direction())),
  432. };
  433. case CSS::PropertyID::FlexWrap:
  434. return StyleProperty {
  435. .property_id = property_id,
  436. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_wrap())),
  437. };
  438. case CSS::PropertyID::FlexBasis: {
  439. switch (layout_node.computed_values().flex_basis().type) {
  440. case FlexBasis::Content:
  441. return StyleProperty {
  442. .property_id = property_id,
  443. .value = IdentifierStyleValue::create(CSS::ValueID::Content),
  444. };
  445. case FlexBasis::Length:
  446. return StyleProperty {
  447. .property_id = property_id,
  448. .value = LengthStyleValue::create(layout_node.computed_values().flex_basis().length),
  449. };
  450. case FlexBasis::Auto:
  451. return StyleProperty {
  452. .property_id = property_id,
  453. .value = IdentifierStyleValue::create(CSS::ValueID::Auto),
  454. };
  455. }
  456. VERIFY_NOT_REACHED();
  457. }
  458. case CSS::PropertyID::FlexGrow: {
  459. auto maybe_grow_factor = layout_node.computed_values().flex_grow_factor();
  460. if (!maybe_grow_factor.has_value())
  461. return {};
  462. return StyleProperty {
  463. .property_id = property_id,
  464. .value = NumericStyleValue::create(maybe_grow_factor.release_value()),
  465. };
  466. }
  467. case CSS::PropertyID::FlexShrink: {
  468. auto maybe_shrink_factor = layout_node.computed_values().flex_shrink_factor();
  469. if (!maybe_shrink_factor.has_value())
  470. return {};
  471. return StyleProperty {
  472. .property_id = property_id,
  473. .value = NumericStyleValue::create(maybe_shrink_factor.release_value()),
  474. };
  475. }
  476. case CSS::PropertyID::Opacity: {
  477. auto maybe_opacity = layout_node.computed_values().opacity();
  478. if (!maybe_opacity.has_value())
  479. return {};
  480. return StyleProperty {
  481. .property_id = property_id,
  482. .value = NumericStyleValue::create(maybe_opacity.release_value()),
  483. };
  484. }
  485. case CSS::PropertyID::JustifyContent:
  486. return StyleProperty {
  487. .property_id = property_id,
  488. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().justify_content())),
  489. };
  490. case CSS::PropertyID::BoxShadow: {
  491. auto maybe_box_shadow = layout_node.computed_values().box_shadow();
  492. if (!maybe_box_shadow.has_value())
  493. return {};
  494. auto box_shadow_data = maybe_box_shadow.release_value();
  495. return StyleProperty {
  496. .property_id = property_id,
  497. .value = BoxShadowStyleValue::create(box_shadow_data.offset_x, box_shadow_data.offset_y, box_shadow_data.blur_radius, box_shadow_data.color),
  498. };
  499. }
  500. case CSS::PropertyID::Width:
  501. return StyleProperty {
  502. .property_id = property_id,
  503. .value = LengthStyleValue::create(layout_node.computed_values().width()),
  504. };
  505. case CSS::PropertyID::MinWidth:
  506. return StyleProperty {
  507. .property_id = property_id,
  508. .value = LengthStyleValue::create(layout_node.computed_values().min_width()),
  509. };
  510. case CSS::PropertyID::MaxWidth:
  511. return StyleProperty {
  512. .property_id = property_id,
  513. .value = LengthStyleValue::create(layout_node.computed_values().max_width()),
  514. };
  515. case CSS::PropertyID::Height:
  516. return StyleProperty {
  517. .property_id = property_id,
  518. .value = LengthStyleValue::create(layout_node.computed_values().height()),
  519. };
  520. case CSS::PropertyID::MinHeight:
  521. return StyleProperty {
  522. .property_id = property_id,
  523. .value = LengthStyleValue::create(layout_node.computed_values().min_height()),
  524. };
  525. case CSS::PropertyID::MaxHeight:
  526. return StyleProperty {
  527. .property_id = property_id,
  528. .value = LengthStyleValue::create(layout_node.computed_values().max_height()),
  529. };
  530. case CSS::PropertyID::MarginTop:
  531. return StyleProperty {
  532. .property_id = property_id,
  533. .value = LengthStyleValue::create(layout_node.computed_values().margin().top),
  534. };
  535. case CSS::PropertyID::MarginRight:
  536. return StyleProperty {
  537. .property_id = property_id,
  538. .value = LengthStyleValue::create(layout_node.computed_values().margin().right),
  539. };
  540. case CSS::PropertyID::MarginBottom:
  541. return StyleProperty {
  542. .property_id = property_id,
  543. .value = LengthStyleValue::create(layout_node.computed_values().margin().bottom),
  544. };
  545. case CSS::PropertyID::MarginLeft:
  546. return StyleProperty {
  547. .property_id = property_id,
  548. .value = LengthStyleValue::create(layout_node.computed_values().margin().left),
  549. };
  550. case CSS::PropertyID::PaddingTop:
  551. return StyleProperty {
  552. .property_id = property_id,
  553. .value = LengthStyleValue::create(layout_node.computed_values().padding().top),
  554. };
  555. case CSS::PropertyID::PaddingRight:
  556. return StyleProperty {
  557. .property_id = property_id,
  558. .value = LengthStyleValue::create(layout_node.computed_values().padding().right),
  559. };
  560. case CSS::PropertyID::PaddingBottom:
  561. return StyleProperty {
  562. .property_id = property_id,
  563. .value = LengthStyleValue::create(layout_node.computed_values().padding().bottom),
  564. };
  565. case CSS::PropertyID::PaddingLeft:
  566. return StyleProperty {
  567. .property_id = property_id,
  568. .value = LengthStyleValue::create(layout_node.computed_values().padding().left),
  569. };
  570. case CSS::PropertyID::BorderRadius: {
  571. auto maybe_top_left_radius = property(CSS::PropertyID::BorderTopLeftRadius);
  572. auto maybe_top_right_radius = property(CSS::PropertyID::BorderTopRightRadius);
  573. auto maybe_bottom_left_radius = property(CSS::PropertyID::BorderBottomLeftRadius);
  574. auto maybe_bottom_right_radius = property(CSS::PropertyID::BorderBottomRightRadius);
  575. RefPtr<BorderRadiusStyleValue> top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius;
  576. if (maybe_top_left_radius.has_value()) {
  577. VERIFY(maybe_top_left_radius.value().value->type() == StyleValue::Type::BorderRadius);
  578. top_left_radius = *static_cast<BorderRadiusStyleValue*>(maybe_top_left_radius.value().value.ptr());
  579. }
  580. if (maybe_top_right_radius.has_value()) {
  581. VERIFY(maybe_top_right_radius.value().value->type() == StyleValue::Type::BorderRadius);
  582. top_right_radius = *static_cast<BorderRadiusStyleValue*>(maybe_top_right_radius.value().value.ptr());
  583. }
  584. if (maybe_bottom_left_radius.has_value()) {
  585. VERIFY(maybe_bottom_left_radius.value().value->type() == StyleValue::Type::BorderRadius);
  586. bottom_left_radius = *static_cast<BorderRadiusStyleValue*>(maybe_bottom_left_radius.value().value.ptr());
  587. }
  588. if (maybe_bottom_right_radius.has_value()) {
  589. VERIFY(maybe_bottom_right_radius.value().value->type() == StyleValue::Type::BorderRadius);
  590. bottom_right_radius = *static_cast<BorderRadiusStyleValue*>(maybe_bottom_right_radius.value().value.ptr());
  591. }
  592. return StyleProperty {
  593. .property_id = property_id,
  594. .value = CombinedBorderRadiusStyleValue::create(top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull()),
  595. };
  596. }
  597. // FIXME: The two radius components are not yet stored, as we currently don't actually render them.
  598. case CSS::PropertyID::BorderBottomLeftRadius:
  599. return StyleProperty {
  600. .property_id = property_id,
  601. .value = BorderRadiusStyleValue::create(layout_node.computed_values().border_bottom_left_radius(), layout_node.computed_values().border_bottom_left_radius()),
  602. };
  603. case CSS::PropertyID::BorderBottomRightRadius:
  604. return StyleProperty {
  605. .property_id = property_id,
  606. .value = BorderRadiusStyleValue::create(layout_node.computed_values().border_bottom_right_radius(), layout_node.computed_values().border_bottom_right_radius()),
  607. };
  608. case CSS::PropertyID::BorderTopLeftRadius:
  609. return StyleProperty {
  610. .property_id = property_id,
  611. .value = BorderRadiusStyleValue::create(layout_node.computed_values().border_top_left_radius(), layout_node.computed_values().border_top_left_radius()),
  612. };
  613. case CSS::PropertyID::BorderTopRightRadius:
  614. return StyleProperty {
  615. .property_id = property_id,
  616. .value = BorderRadiusStyleValue::create(layout_node.computed_values().border_top_right_radius(), layout_node.computed_values().border_top_right_radius()),
  617. };
  618. case CSS::PropertyID::OverflowX:
  619. return StyleProperty {
  620. .property_id = property_id,
  621. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_x())),
  622. };
  623. case CSS::PropertyID::OverflowY:
  624. return StyleProperty {
  625. .property_id = property_id,
  626. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_y())),
  627. };
  628. case CSS::PropertyID::Color:
  629. return StyleProperty {
  630. .property_id = property_id,
  631. .value = ColorStyleValue::create(layout_node.computed_values().color()),
  632. };
  633. case PropertyID::BackgroundColor:
  634. return StyleProperty {
  635. .property_id = property_id,
  636. .value = ColorStyleValue::create(layout_node.computed_values().background_color()),
  637. };
  638. case CSS::PropertyID::BackgroundRepeatX:
  639. return StyleProperty {
  640. .property_id = property_id,
  641. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().background_repeat_x())),
  642. };
  643. case CSS::PropertyID::BackgroundRepeatY:
  644. return StyleProperty {
  645. .property_id = property_id,
  646. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().background_repeat_y())),
  647. };
  648. case CSS::PropertyID::BackgroundRepeat: {
  649. auto maybe_background_repeat_x = property(CSS::PropertyID::BackgroundRepeatX);
  650. auto maybe_background_repeat_y = property(CSS::PropertyID::BackgroundRepeatY);
  651. return StyleProperty {
  652. .property_id = property_id,
  653. .value = 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))),
  654. };
  655. }
  656. case CSS::PropertyID::Background: {
  657. auto maybe_background_color = property(CSS::PropertyID::BackgroundColor);
  658. auto maybe_background_image = property(CSS::PropertyID::BackgroundImage);
  659. auto maybe_background_repeat_x = property(CSS::PropertyID::BackgroundRepeatX);
  660. auto maybe_background_repeat_y = property(CSS::PropertyID::BackgroundRepeatY);
  661. return StyleProperty {
  662. .property_id = property_id,
  663. .value = 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))),
  664. };
  665. }
  666. case CSS::PropertyID::ListStyleType:
  667. return StyleProperty {
  668. .property_id = property_id,
  669. .value = IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().list_style_type())),
  670. };
  671. case CSS::PropertyID::Invalid:
  672. return StyleProperty {
  673. .property_id = property_id,
  674. .value = IdentifierStyleValue::create(CSS::ValueID::Invalid),
  675. };
  676. case CSS::PropertyID::Custom:
  677. dbgln("Computed style for custom properties was requested (?)");
  678. return {};
  679. default:
  680. dbgln("FIXME: Computed style for the '{}' property was requested", string_from_property_id(property_id));
  681. return {};
  682. }
  683. }
  684. bool ComputedCSSStyleDeclaration::set_property(PropertyID, StringView)
  685. {
  686. return false;
  687. }
  688. }