ResolvedCSSStyleDeclaration.cpp 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. * Copyright (c) 2021-2022, 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/Debug.h>
  8. #include <AK/NonnullRefPtr.h>
  9. #include <LibWeb/CSS/Enums.h>
  10. #include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
  11. #include <LibWeb/CSS/StyleComputer.h>
  12. #include <LibWeb/DOM/Document.h>
  13. #include <LibWeb/DOM/Element.h>
  14. namespace Web::CSS {
  15. ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element)
  16. : m_element(element)
  17. {
  18. }
  19. size_t ResolvedCSSStyleDeclaration::length() const
  20. {
  21. return 0;
  22. }
  23. String ResolvedCSSStyleDeclaration::item(size_t index) const
  24. {
  25. (void)index;
  26. return {};
  27. }
  28. static RefPtr<StyleValue> style_value_for_display(CSS::Display display)
  29. {
  30. if (display.is_none())
  31. return IdentifierStyleValue::create(CSS::ValueID::None);
  32. if (display.is_outside_and_inside()) {
  33. NonnullRefPtrVector<StyleValue> values;
  34. switch (display.outside()) {
  35. case CSS::Display::Outside::Inline:
  36. values.append(IdentifierStyleValue::create(CSS::ValueID::Inline));
  37. break;
  38. case CSS::Display::Outside::Block:
  39. values.append(IdentifierStyleValue::create(CSS::ValueID::Block));
  40. break;
  41. case CSS::Display::Outside::RunIn:
  42. values.append(IdentifierStyleValue::create(CSS::ValueID::RunIn));
  43. break;
  44. }
  45. switch (display.inside()) {
  46. case CSS::Display::Inside::Flow:
  47. values.append(IdentifierStyleValue::create(CSS::ValueID::Flow));
  48. break;
  49. case CSS::Display::Inside::FlowRoot:
  50. values.append(IdentifierStyleValue::create(CSS::ValueID::FlowRoot));
  51. break;
  52. case CSS::Display::Inside::Table:
  53. values.append(IdentifierStyleValue::create(CSS::ValueID::Table));
  54. break;
  55. case CSS::Display::Inside::Flex:
  56. values.append(IdentifierStyleValue::create(CSS::ValueID::Flex));
  57. break;
  58. case CSS::Display::Inside::Grid:
  59. values.append(IdentifierStyleValue::create(CSS::ValueID::Grid));
  60. break;
  61. case CSS::Display::Inside::Ruby:
  62. values.append(IdentifierStyleValue::create(CSS::ValueID::Ruby));
  63. break;
  64. }
  65. return StyleValueList::create(move(values), StyleValueList::Separator::Space);
  66. }
  67. if (display.is_internal()) {
  68. switch (display.internal()) {
  69. case CSS::Display::Internal::TableRowGroup:
  70. return IdentifierStyleValue::create(CSS::ValueID::TableRowGroup);
  71. case CSS::Display::Internal::TableHeaderGroup:
  72. return IdentifierStyleValue::create(CSS::ValueID::TableHeaderGroup);
  73. case CSS::Display::Internal::TableFooterGroup:
  74. return IdentifierStyleValue::create(CSS::ValueID::TableFooterGroup);
  75. case CSS::Display::Internal::TableRow:
  76. return IdentifierStyleValue::create(CSS::ValueID::TableRow);
  77. case CSS::Display::Internal::TableCell:
  78. return IdentifierStyleValue::create(CSS::ValueID::TableCell);
  79. case CSS::Display::Internal::TableColumnGroup:
  80. return IdentifierStyleValue::create(CSS::ValueID::TableColumnGroup);
  81. case CSS::Display::Internal::TableColumn:
  82. return IdentifierStyleValue::create(CSS::ValueID::TableColumn);
  83. case CSS::Display::Internal::TableCaption:
  84. return IdentifierStyleValue::create(CSS::ValueID::TableCaption);
  85. case CSS::Display::Internal::RubyBase:
  86. return IdentifierStyleValue::create(CSS::ValueID::RubyBase);
  87. case CSS::Display::Internal::RubyText:
  88. return IdentifierStyleValue::create(CSS::ValueID::RubyText);
  89. case CSS::Display::Internal::RubyBaseContainer:
  90. return IdentifierStyleValue::create(CSS::ValueID::RubyBaseContainer);
  91. case CSS::Display::Internal::RubyTextContainer:
  92. return IdentifierStyleValue::create(CSS::ValueID::RubyTextContainer);
  93. }
  94. }
  95. TODO();
  96. }
  97. static NonnullRefPtr<StyleValue> value_or_default(Optional<StyleProperty> property, NonnullRefPtr<StyleValue> default_style)
  98. {
  99. if (property.has_value())
  100. return property.value().value;
  101. return default_style;
  102. }
  103. static NonnullRefPtr<StyleValue> style_value_for_length_percentage(LengthPercentage const& length_percentage)
  104. {
  105. if (length_percentage.is_percentage())
  106. return PercentageStyleValue::create(length_percentage.percentage());
  107. if (length_percentage.is_length())
  108. return LengthStyleValue::create(length_percentage.length());
  109. return length_percentage.calculated();
  110. }
  111. RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const
  112. {
  113. switch (property_id) {
  114. case CSS::PropertyID::Float:
  115. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().float_()));
  116. case CSS::PropertyID::Clear:
  117. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().clear()));
  118. case CSS::PropertyID::Cursor:
  119. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().cursor()));
  120. case CSS::PropertyID::Display:
  121. return style_value_for_display(layout_node.computed_values().display());
  122. case CSS::PropertyID::ZIndex: {
  123. auto maybe_z_index = layout_node.computed_values().z_index();
  124. if (!maybe_z_index.has_value())
  125. return {};
  126. return NumericStyleValue::create_integer(maybe_z_index.release_value());
  127. }
  128. case CSS::PropertyID::TextAlign:
  129. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().text_align()));
  130. case CSS::PropertyID::TextDecorationLine: {
  131. auto text_decoration_lines = layout_node.computed_values().text_decoration_line();
  132. if (text_decoration_lines.is_empty())
  133. return IdentifierStyleValue::create(ValueID::None);
  134. NonnullRefPtrVector<StyleValue> style_values;
  135. for (auto const& line : text_decoration_lines) {
  136. style_values.append(IdentifierStyleValue::create(to_value_id(line)));
  137. }
  138. return StyleValueList::create(move(style_values), StyleValueList::Separator::Space);
  139. }
  140. case CSS::PropertyID::TextDecorationStyle:
  141. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().text_decoration_style()));
  142. case CSS::PropertyID::TextTransform:
  143. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().text_transform()));
  144. case CSS::PropertyID::Position:
  145. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().position()));
  146. case CSS::PropertyID::WhiteSpace:
  147. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().white_space()));
  148. case CSS::PropertyID::FlexDirection:
  149. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().flex_direction()));
  150. case CSS::PropertyID::FlexWrap:
  151. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().flex_wrap()));
  152. case CSS::PropertyID::FlexBasis: {
  153. switch (layout_node.computed_values().flex_basis().type) {
  154. case FlexBasis::Content:
  155. return IdentifierStyleValue::create(CSS::ValueID::Content);
  156. case FlexBasis::LengthPercentage:
  157. return style_value_for_length_percentage(*layout_node.computed_values().flex_basis().length_percentage);
  158. case FlexBasis::Auto:
  159. return IdentifierStyleValue::create(CSS::ValueID::Auto);
  160. default:
  161. VERIFY_NOT_REACHED();
  162. }
  163. break;
  164. case CSS::PropertyID::FlexGrow:
  165. return NumericStyleValue::create_float(layout_node.computed_values().flex_grow());
  166. case CSS::PropertyID::FlexShrink:
  167. return NumericStyleValue::create_float(layout_node.computed_values().flex_shrink());
  168. case CSS::PropertyID::Order:
  169. return NumericStyleValue::create_integer(layout_node.computed_values().order());
  170. case CSS::PropertyID::Opacity:
  171. return NumericStyleValue::create_float(layout_node.computed_values().opacity());
  172. case CSS::PropertyID::ImageRendering:
  173. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().image_rendering()));
  174. case CSS::PropertyID::JustifyContent:
  175. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().justify_content()));
  176. case CSS::PropertyID::BoxShadow: {
  177. auto box_shadow_layers = layout_node.computed_values().box_shadow();
  178. if (box_shadow_layers.is_empty())
  179. return {};
  180. auto make_box_shadow_style_value = [](ShadowData const& data) {
  181. return ShadowStyleValue::create(data.color, data.offset_x, data.offset_y, data.blur_radius, data.spread_distance, data.placement);
  182. };
  183. if (box_shadow_layers.size() == 1)
  184. return make_box_shadow_style_value(box_shadow_layers.first());
  185. NonnullRefPtrVector<StyleValue> box_shadow;
  186. box_shadow.ensure_capacity(box_shadow_layers.size());
  187. for (auto const& layer : box_shadow_layers)
  188. box_shadow.append(make_box_shadow_style_value(layer));
  189. return StyleValueList::create(move(box_shadow), StyleValueList::Separator::Comma);
  190. }
  191. case CSS::PropertyID::Width:
  192. return style_value_for_length_percentage(layout_node.computed_values().width());
  193. case CSS::PropertyID::MinWidth:
  194. return style_value_for_length_percentage(layout_node.computed_values().min_width());
  195. case CSS::PropertyID::MaxWidth:
  196. return style_value_for_length_percentage(layout_node.computed_values().max_width());
  197. case CSS::PropertyID::Height:
  198. return style_value_for_length_percentage(layout_node.computed_values().height());
  199. case CSS::PropertyID::MinHeight:
  200. return style_value_for_length_percentage(layout_node.computed_values().min_height());
  201. case CSS::PropertyID::MaxHeight:
  202. return style_value_for_length_percentage(layout_node.computed_values().max_height());
  203. case CSS::PropertyID::Margin: {
  204. auto margin = layout_node.computed_values().margin();
  205. auto values = NonnullRefPtrVector<StyleValue> {};
  206. values.append(style_value_for_length_percentage(margin.top));
  207. values.append(style_value_for_length_percentage(margin.right));
  208. values.append(style_value_for_length_percentage(margin.bottom));
  209. values.append(style_value_for_length_percentage(margin.left));
  210. return StyleValueList::create(move(values), StyleValueList::Separator::Space);
  211. }
  212. case CSS::PropertyID::MarginTop:
  213. return style_value_for_length_percentage(layout_node.computed_values().margin().top);
  214. case CSS::PropertyID::MarginRight:
  215. return style_value_for_length_percentage(layout_node.computed_values().margin().right);
  216. case CSS::PropertyID::MarginBottom:
  217. return style_value_for_length_percentage(layout_node.computed_values().margin().bottom);
  218. case CSS::PropertyID::MarginLeft:
  219. return style_value_for_length_percentage(layout_node.computed_values().margin().left);
  220. case CSS::PropertyID::Padding: {
  221. auto padding = layout_node.computed_values().padding();
  222. auto values = NonnullRefPtrVector<StyleValue> {};
  223. values.append(style_value_for_length_percentage(padding.top));
  224. values.append(style_value_for_length_percentage(padding.right));
  225. values.append(style_value_for_length_percentage(padding.bottom));
  226. values.append(style_value_for_length_percentage(padding.left));
  227. return StyleValueList::create(move(values), StyleValueList::Separator::Space);
  228. }
  229. case CSS::PropertyID::PaddingTop:
  230. return style_value_for_length_percentage(layout_node.computed_values().padding().top);
  231. case CSS::PropertyID::PaddingRight:
  232. return style_value_for_length_percentage(layout_node.computed_values().padding().right);
  233. case CSS::PropertyID::PaddingBottom:
  234. return style_value_for_length_percentage(layout_node.computed_values().padding().bottom);
  235. case CSS::PropertyID::PaddingLeft:
  236. return style_value_for_length_percentage(layout_node.computed_values().padding().left);
  237. case CSS::PropertyID::BorderRadius: {
  238. auto maybe_top_left_radius = property(CSS::PropertyID::BorderTopLeftRadius);
  239. auto maybe_top_right_radius = property(CSS::PropertyID::BorderTopRightRadius);
  240. auto maybe_bottom_left_radius = property(CSS::PropertyID::BorderBottomLeftRadius);
  241. auto maybe_bottom_right_radius = property(CSS::PropertyID::BorderBottomRightRadius);
  242. RefPtr<BorderRadiusStyleValue> top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius;
  243. if (maybe_top_left_radius.has_value()) {
  244. VERIFY(maybe_top_left_radius.value().value->is_border_radius());
  245. top_left_radius = maybe_top_left_radius.value().value->as_border_radius();
  246. }
  247. if (maybe_top_right_radius.has_value()) {
  248. VERIFY(maybe_top_right_radius.value().value->is_border_radius());
  249. top_right_radius = maybe_top_right_radius.value().value->as_border_radius();
  250. }
  251. if (maybe_bottom_left_radius.has_value()) {
  252. VERIFY(maybe_bottom_left_radius.value().value->is_border_radius());
  253. bottom_left_radius = maybe_bottom_left_radius.value().value->as_border_radius();
  254. }
  255. if (maybe_bottom_right_radius.has_value()) {
  256. VERIFY(maybe_bottom_right_radius.value().value->is_border_radius());
  257. bottom_right_radius = maybe_bottom_right_radius.value().value->as_border_radius();
  258. }
  259. return BorderRadiusShorthandStyleValue::create(top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull());
  260. }
  261. // FIXME: The two radius components are not yet stored, as we currently don't actually render them.
  262. case CSS::PropertyID::BorderBottomLeftRadius: {
  263. auto const& border_radius = layout_node.computed_values().border_bottom_left_radius();
  264. return BorderRadiusStyleValue::create(border_radius.horizontal_radius, border_radius.vertical_radius);
  265. }
  266. case CSS::PropertyID::BorderBottomRightRadius: {
  267. auto const& border_radius = layout_node.computed_values().border_bottom_right_radius();
  268. return BorderRadiusStyleValue::create(border_radius.horizontal_radius, border_radius.vertical_radius);
  269. }
  270. case CSS::PropertyID::BorderTopLeftRadius: {
  271. auto const& border_radius = layout_node.computed_values().border_top_left_radius();
  272. return BorderRadiusStyleValue::create(border_radius.horizontal_radius, border_radius.vertical_radius);
  273. }
  274. case CSS::PropertyID::BorderTopRightRadius: {
  275. auto const& border_radius = layout_node.computed_values().border_top_right_radius();
  276. return BorderRadiusStyleValue::create(border_radius.horizontal_radius, border_radius.vertical_radius);
  277. }
  278. case CSS::PropertyID::BorderTopWidth:
  279. return LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_top().width));
  280. case CSS::PropertyID::BorderRightWidth:
  281. return LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_right().width));
  282. case CSS::PropertyID::BorderBottomWidth:
  283. return LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_bottom().width));
  284. case CSS::PropertyID::BorderLeftWidth:
  285. return LengthStyleValue::create(Length::make_px(layout_node.computed_values().border_left().width));
  286. case CSS::PropertyID::BorderTopColor:
  287. return ColorStyleValue::create(layout_node.computed_values().border_top().color);
  288. case CSS::PropertyID::BorderRightColor:
  289. return ColorStyleValue::create(layout_node.computed_values().border_right().color);
  290. case CSS::PropertyID::BorderBottomColor:
  291. return ColorStyleValue::create(layout_node.computed_values().border_bottom().color);
  292. case CSS::PropertyID::BorderLeftColor:
  293. return ColorStyleValue::create(layout_node.computed_values().border_left().color);
  294. case CSS::PropertyID::BorderTopStyle:
  295. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_top().line_style));
  296. case CSS::PropertyID::BorderRightStyle:
  297. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_right().line_style));
  298. case CSS::PropertyID::BorderBottomStyle:
  299. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_bottom().line_style));
  300. case CSS::PropertyID::BorderLeftStyle:
  301. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().border_left().line_style));
  302. case CSS::PropertyID::BorderTop: {
  303. auto border = layout_node.computed_values().border_top();
  304. auto width = LengthStyleValue::create(Length::make_px(border.width));
  305. auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
  306. auto color = ColorStyleValue::create(border.color);
  307. return BorderStyleValue::create(width, style, color);
  308. }
  309. case CSS::PropertyID::BorderRight: {
  310. auto border = layout_node.computed_values().border_right();
  311. auto width = LengthStyleValue::create(Length::make_px(border.width));
  312. auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
  313. auto color = ColorStyleValue::create(border.color);
  314. return BorderStyleValue::create(width, style, color);
  315. }
  316. case CSS::PropertyID::BorderBottom: {
  317. auto border = layout_node.computed_values().border_bottom();
  318. auto width = LengthStyleValue::create(Length::make_px(border.width));
  319. auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
  320. auto color = ColorStyleValue::create(border.color);
  321. return BorderStyleValue::create(width, style, color);
  322. }
  323. case CSS::PropertyID::BorderLeft: {
  324. auto border = layout_node.computed_values().border_left();
  325. auto width = LengthStyleValue::create(Length::make_px(border.width));
  326. auto style = IdentifierStyleValue::create(to_value_id(border.line_style));
  327. auto color = ColorStyleValue::create(border.color);
  328. return BorderStyleValue::create(width, style, color);
  329. }
  330. case CSS::PropertyID::OverflowX:
  331. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().overflow_x()));
  332. case CSS::PropertyID::OverflowY:
  333. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().overflow_y()));
  334. case CSS::PropertyID::Color:
  335. return ColorStyleValue::create(layout_node.computed_values().color());
  336. case PropertyID::BackgroundColor:
  337. return ColorStyleValue::create(layout_node.computed_values().background_color());
  338. case CSS::PropertyID::Background: {
  339. auto maybe_background_color = property(CSS::PropertyID::BackgroundColor);
  340. auto maybe_background_image = property(CSS::PropertyID::BackgroundImage);
  341. auto maybe_background_position = property(CSS::PropertyID::BackgroundPosition);
  342. auto maybe_background_size = property(CSS::PropertyID::BackgroundSize);
  343. auto maybe_background_repeat = property(CSS::PropertyID::BackgroundRepeat);
  344. auto maybe_background_attachment = property(CSS::PropertyID::BackgroundAttachment);
  345. auto maybe_background_origin = property(CSS::PropertyID::BackgroundOrigin);
  346. auto maybe_background_clip = property(CSS::PropertyID::BackgroundClip);
  347. return BackgroundStyleValue::create(
  348. value_or_default(maybe_background_color, InitialStyleValue::the()),
  349. value_or_default(maybe_background_image, IdentifierStyleValue::create(CSS::ValueID::None)),
  350. value_or_default(maybe_background_position, PositionStyleValue::create(PositionEdge::Left, Length::make_px(0), PositionEdge::Top, Length::make_px(0))),
  351. value_or_default(maybe_background_size, IdentifierStyleValue::create(CSS::ValueID::Auto)),
  352. value_or_default(maybe_background_repeat, BackgroundRepeatStyleValue::create(CSS::Repeat::Repeat, CSS::Repeat::Repeat)),
  353. value_or_default(maybe_background_attachment, IdentifierStyleValue::create(CSS::ValueID::Scroll)),
  354. value_or_default(maybe_background_origin, IdentifierStyleValue::create(CSS::ValueID::PaddingBox)),
  355. value_or_default(maybe_background_clip, IdentifierStyleValue::create(CSS::ValueID::BorderBox)));
  356. }
  357. case CSS::PropertyID::VerticalAlign:
  358. if (auto const* length_percentage = layout_node.computed_values().vertical_align().get_pointer<CSS::LengthPercentage>()) {
  359. if (length_percentage->is_length())
  360. return LengthStyleValue::create(length_percentage->length());
  361. if (length_percentage->is_percentage())
  362. return PercentageStyleValue::create(length_percentage->percentage());
  363. VERIFY_NOT_REACHED();
  364. }
  365. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().vertical_align().get<CSS::VerticalAlign>()));
  366. case CSS::PropertyID::ListStyleType:
  367. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().list_style_type()));
  368. case CSS::PropertyID::BoxSizing:
  369. return IdentifierStyleValue::create(to_value_id(layout_node.computed_values().box_sizing()));
  370. case CSS::PropertyID::Invalid:
  371. return IdentifierStyleValue::create(CSS::ValueID::Invalid);
  372. case CSS::PropertyID::Custom:
  373. dbgln_if(LIBWEB_CSS_DEBUG, "Computed style for custom properties was requested (?)");
  374. return {};
  375. default:
  376. dbgln_if(LIBWEB_CSS_DEBUG, "FIXME: Computed style for the '{}' property was requested", string_from_property_id(property_id));
  377. return {};
  378. }
  379. }
  380. }
  381. Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID property_id) const
  382. {
  383. if (CSS::property_affects_layout(property_id)) {
  384. const_cast<DOM::Document&>(m_element->document()).update_layout();
  385. } else {
  386. // FIXME: If we had a way to update style for a single element, this would be a good place to use it.
  387. const_cast<DOM::Document&>(m_element->document()).update_style();
  388. }
  389. if (!m_element->layout_node()) {
  390. auto style = m_element->document().style_computer().compute_style(const_cast<DOM::Element&>(*m_element));
  391. return StyleProperty {
  392. .property_id = property_id,
  393. .value = style->property(property_id),
  394. };
  395. }
  396. auto& layout_node = *m_element->layout_node();
  397. auto value = style_value_for_property(layout_node, property_id);
  398. if (!value)
  399. return {};
  400. return StyleProperty {
  401. .property_id = property_id,
  402. .value = value.release_nonnull(),
  403. };
  404. }
  405. // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-setproperty
  406. DOM::ExceptionOr<void> ResolvedCSSStyleDeclaration::set_property(PropertyID, StringView, StringView)
  407. {
  408. // 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
  409. return DOM::NoModificationAllowedError::create("Cannot modify properties in result of getComputedStyle()");
  410. }
  411. // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty
  412. DOM::ExceptionOr<String> ResolvedCSSStyleDeclaration::remove_property(PropertyID)
  413. {
  414. // 1. If the computed flag is set, then throw a NoModificationAllowedError exception.
  415. return DOM::NoModificationAllowedError::create("Cannot remove properties from result of getComputedStyle()");
  416. }
  417. String ResolvedCSSStyleDeclaration::serialized() const
  418. {
  419. // https://www.w3.org/TR/cssom/#dom-cssstyledeclaration-csstext
  420. // If the computed flag is set, then return the empty string.
  421. // NOTE: ResolvedCSSStyleDeclaration is something you would only get from window.getComputedStyle(),
  422. // which returns what the spec calls "resolved style". The "computed flag" is always set here.
  423. return String::empty();
  424. }
  425. }