summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/CSS/ResolvedCSSStyleDeclaration.cpp
blob: 6ab3388d13c29cd4a9d3f97a1a5de142e8815744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
/*
 * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
 * Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <AK/NonnullRefPtr.h>
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
#include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Element.h>

namespace Web::CSS {

ResolvedCSSStyleDeclaration::ResolvedCSSStyleDeclaration(DOM::Element& element)
    : m_element(element)
{
}

ResolvedCSSStyleDeclaration::~ResolvedCSSStyleDeclaration()
{
}

size_t ResolvedCSSStyleDeclaration::length() const
{
    return 0;
}

String ResolvedCSSStyleDeclaration::item(size_t index) const
{
    (void)index;
    return {};
}

static CSS::ValueID to_css_value_id(CSS::BoxSizing value)
{
    switch (value) {
    case CSS::BoxSizing::BorderBox:
        return CSS::ValueID::BorderBox;
    case CSS::BoxSizing::ContentBox:
        return CSS::ValueID::ContentBox;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::Display value)
{
    switch (value) {
    case CSS::Display::None:
        return CSS::ValueID::None;
    case CSS::Display::Block:
        return CSS::ValueID::Block;
    case CSS::Display::Inline:
        return CSS::ValueID::Inline;
    case CSS::Display::InlineBlock:
        return CSS::ValueID::InlineBlock;
    case CSS::Display::ListItem:
        return CSS::ValueID::ListItem;
    case CSS::Display::Table:
        return CSS::ValueID::Table;
    case CSS::Display::TableRow:
        return CSS::ValueID::TableRow;
    case CSS::Display::TableCell:
        return CSS::ValueID::TableCell;
    case CSS::Display::TableHeaderGroup:
        return CSS::ValueID::TableHeaderGroup;
    case CSS::Display::TableRowGroup:
        return CSS::ValueID::TableRowGroup;
    case CSS::Display::TableFooterGroup:
        return CSS::ValueID::TableFooterGroup;
    case CSS::Display::TableColumn:
        return CSS::ValueID::TableColumn;
    case CSS::Display::TableColumnGroup:
        return CSS::ValueID::TableColumnGroup;
    case CSS::Display::TableCaption:
        return CSS::ValueID::TableCaption;
    case CSS::Display::Flex:
        return CSS::ValueID::Flex;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::Float value)
{
    switch (value) {
    case Float::None:
        return CSS::ValueID::None;
    case Float::Left:
        return CSS::ValueID::Left;
    case Float::Right:
        return CSS::ValueID::Right;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::Clear value)
{
    switch (value) {
    case Clear::None:
        return CSS::ValueID::None;
    case Clear::Left:
        return CSS::ValueID::Left;
    case Clear::Right:
        return CSS::ValueID::Right;
    case Clear::Both:
        return CSS::ValueID::Both;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::TextDecorationLine value)
{
    switch (value) {
    case TextDecorationLine::None:
        return CSS::ValueID::None;
    case TextDecorationLine::Underline:
        return CSS::ValueID::Underline;
    case TextDecorationLine::Overline:
        return CSS::ValueID::Overline;
    case TextDecorationLine::LineThrough:
        return CSS::ValueID::LineThrough;
    case TextDecorationLine::Blink:
        return CSS::ValueID::Blink;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::Cursor value)
{
    switch (value) {
    case Cursor::Auto:
        return CSS::ValueID::Auto;
    case Cursor::Default:
        return CSS::ValueID::Default;
    case Cursor::None:
        return CSS::ValueID::None;
    case Cursor::ContextMenu:
        return CSS::ValueID::ContextMenu;
    case Cursor::Help:
        return CSS::ValueID::Help;
    case Cursor::Pointer:
        return CSS::ValueID::Pointer;
    case Cursor::Progress:
        return CSS::ValueID::Progress;
    case Cursor::Wait:
        return CSS::ValueID::Wait;
    case Cursor::Cell:
        return CSS::ValueID::Cell;
    case Cursor::Crosshair:
        return CSS::ValueID::Crosshair;
    case Cursor::Text:
        return CSS::ValueID::Text;
    case Cursor::VerticalText:
        return CSS::ValueID::VerticalText;
    case Cursor::Alias:
        return CSS::ValueID::Alias;
    case Cursor::Copy:
        return CSS::ValueID::Copy;
    case Cursor::Move:
        return CSS::ValueID::Move;
    case Cursor::NoDrop:
        return CSS::ValueID::NoDrop;
    case Cursor::NotAllowed:
        return CSS::ValueID::NotAllowed;
    case Cursor::Grab:
        return CSS::ValueID::Grab;
    case Cursor::Grabbing:
        return CSS::ValueID::Grabbing;
    case Cursor::EResize:
        return CSS::ValueID::EResize;
    case Cursor::NResize:
        return CSS::ValueID::NResize;
    case Cursor::NeResize:
        return CSS::ValueID::NeResize;
    case Cursor::NwResize:
        return CSS::ValueID::NwResize;
    case Cursor::SResize:
        return CSS::ValueID::SResize;
    case Cursor::SeResize:
        return CSS::ValueID::SeResize;
    case Cursor::SwResize:
        return CSS::ValueID::SwResize;
    case Cursor::WResize:
        return CSS::ValueID::WResize;
    case Cursor::EwResize:
        return CSS::ValueID::EwResize;
    case Cursor::NsResize:
        return CSS::ValueID::NsResize;
    case Cursor::NeswResize:
        return CSS::ValueID::NeswResize;
    case Cursor::NwseResize:
        return CSS::ValueID::NwseResize;
    case Cursor::ColResize:
        return CSS::ValueID::ColResize;
    case Cursor::RowResize:
        return CSS::ValueID::RowResize;
    case Cursor::AllScroll:
        return CSS::ValueID::AllScroll;
    case Cursor::ZoomIn:
        return CSS::ValueID::ZoomIn;
    case Cursor::ZoomOut:
        return CSS::ValueID::ZoomOut;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::TextAlign value)
{
    switch (value) {
    case TextAlign::Left:
        return CSS::ValueID::Left;
    case TextAlign::Center:
        return CSS::ValueID::Center;
    case TextAlign::Right:
        return CSS::ValueID::Right;
    case TextAlign::Justify:
        return CSS::ValueID::Justify;
    case TextAlign::LibwebCenter:
        return CSS::ValueID::LibwebCenter;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::TextTransform value)
{
    switch (value) {
    case TextTransform::None:
        return CSS::ValueID::None;
    case TextTransform::Capitalize:
        return CSS::ValueID::Capitalize;
    case TextTransform::Uppercase:
        return CSS::ValueID::Uppercase;
    case TextTransform::Lowercase:
        return CSS::ValueID::Lowercase;
    case TextTransform::FullWidth:
        return CSS::ValueID::FullWidth;
    case TextTransform::FullSizeKana:
        return CSS::ValueID::FullSizeKana;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::Position value)
{
    switch (value) {
    case Position::Static:
        return CSS::ValueID::Static;
    case Position::Relative:
        return CSS::ValueID::Relative;
    case Position::Absolute:
        return CSS::ValueID::Absolute;
    case Position::Fixed:
        return CSS::ValueID::Fixed;
    case Position::Sticky:
        return CSS::ValueID::Sticky;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::WhiteSpace value)
{
    switch (value) {
    case WhiteSpace::Normal:
        return CSS::ValueID::Normal;
    case WhiteSpace::Pre:
        return CSS::ValueID::Pre;
    case WhiteSpace::Nowrap:
        return CSS::ValueID::Nowrap;
    case WhiteSpace::PreLine:
        return CSS::ValueID::PreLine;
    case WhiteSpace::PreWrap:
        return CSS::ValueID::PreWrap;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::FlexDirection value)
{
    switch (value) {
    case FlexDirection::Row:
        return CSS::ValueID::Row;
    case FlexDirection::RowReverse:
        return CSS::ValueID::RowReverse;
    case FlexDirection::Column:
        return CSS::ValueID::Column;
    case FlexDirection::ColumnReverse:
        return CSS::ValueID::ColumnReverse;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::FlexWrap value)
{
    switch (value) {
    case FlexWrap::Nowrap:
        return CSS::ValueID::Nowrap;
    case FlexWrap::Wrap:
        return CSS::ValueID::Wrap;
    case FlexWrap::WrapReverse:
        return CSS::ValueID::WrapReverse;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::JustifyContent value)
{
    switch (value) {
    case JustifyContent::FlexStart:
        return CSS::ValueID::FlexStart;
    case JustifyContent::FlexEnd:
        return CSS::ValueID::FlexEnd;
    case JustifyContent::Center:
        return CSS::ValueID::Center;
    case JustifyContent::SpaceBetween:
        return CSS::ValueID::SpaceBetween;
    case JustifyContent::SpaceAround:
        return CSS::ValueID::SpaceAround;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::Overflow value)
{
    switch (value) {
    case Overflow::Auto:
        return CSS::ValueID::Auto;
    case Overflow::Clip:
        return CSS::ValueID::Clip;
    case Overflow::Hidden:
        return CSS::ValueID::Hidden;
    case Overflow::Scroll:
        return CSS::ValueID::Scroll;
    case Overflow::Visible:
        return CSS::ValueID::Visible;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::Repeat value)
{
    switch (value) {
    case Repeat::NoRepeat:
        return CSS::ValueID::NoRepeat;
    case Repeat::Repeat:
        return CSS::ValueID::Repeat;
    case Repeat::Round:
        return CSS::ValueID::Round;
    case Repeat::Space:
        return CSS::ValueID::Space;
    }
    VERIFY_NOT_REACHED();
}

static CSS::ValueID to_css_value_id(CSS::ListStyleType value)
{
    switch (value) {
    case ListStyleType::None:
        return CSS::ValueID::None;
    case ListStyleType::Disc:
        return CSS::ValueID::Disc;
    case ListStyleType::Circle:
        return CSS::ValueID::Circle;
    case ListStyleType::Square:
        return CSS::ValueID::Square;
    case ListStyleType::Decimal:
        return CSS::ValueID::Decimal;
    case ListStyleType::DecimalLeadingZero:
        return CSS::ValueID::DecimalLeadingZero;
    case ListStyleType::LowerAlpha:
        return CSS::ValueID::LowerAlpha;
    case ListStyleType::LowerLatin:
        return CSS::ValueID::LowerLatin;
    case ListStyleType::LowerRoman:
        return CSS::ValueID::LowerRoman;
    case ListStyleType::UpperAlpha:
        return CSS::ValueID::UpperAlpha;
    case ListStyleType::UpperLatin:
        return CSS::ValueID::UpperLatin;
    case ListStyleType::UpperRoman:
        return CSS::ValueID::UpperRoman;
    }
    VERIFY_NOT_REACHED();
}

static NonnullRefPtr<StyleValue> value_or_default(Optional<StyleProperty> property, NonnullRefPtr<StyleValue> default_style)
{
    if (property.has_value())
        return property.value().value;
    return default_style;
}

RefPtr<StyleValue> ResolvedCSSStyleDeclaration::style_value_for_property(Layout::NodeWithStyle const& layout_node, PropertyID property_id) const
{
    switch (property_id) {
    case CSS::PropertyID::Float:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().float_()));
    case CSS::PropertyID::Clear:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().clear()));
    case CSS::PropertyID::Cursor:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().cursor()));
    case CSS::PropertyID::Display:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().display()));
    case CSS::PropertyID::ZIndex: {
        auto maybe_z_index = layout_node.computed_values().z_index();
        if (!maybe_z_index.has_value())
            return {};
        return NumericStyleValue::create(maybe_z_index.release_value());
    }
    case CSS::PropertyID::TextAlign:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_align()));
    case CSS::PropertyID::TextDecorationLine:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_decoration_line()));
    case CSS::PropertyID::TextTransform:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().text_transform()));
    case CSS::PropertyID::Position:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().position()));
    case CSS::PropertyID::WhiteSpace:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().white_space()));
    case CSS::PropertyID::FlexDirection:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_direction()));
    case CSS::PropertyID::FlexWrap:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().flex_wrap()));
    case CSS::PropertyID::FlexBasis: {
        switch (layout_node.computed_values().flex_basis().type) {
        case FlexBasis::Content:
            return IdentifierStyleValue::create(CSS::ValueID::Content);
        case FlexBasis::Length:
            return LengthStyleValue::create(layout_node.computed_values().flex_basis().length);
        case FlexBasis::Auto:
            return IdentifierStyleValue::create(CSS::ValueID::Auto);
        default:
            VERIFY_NOT_REACHED();
        }
        break;
    case CSS::PropertyID::FlexGrow: {
        auto maybe_grow_factor = layout_node.computed_values().flex_grow_factor();
        if (!maybe_grow_factor.has_value())
            return {};
        return NumericStyleValue::create(maybe_grow_factor.release_value());
    }
    case CSS::PropertyID::FlexShrink: {
        auto maybe_shrink_factor = layout_node.computed_values().flex_shrink_factor();
        if (!maybe_shrink_factor.has_value())
            return {};
        return NumericStyleValue::create(maybe_shrink_factor.release_value());
    }
    case CSS::PropertyID::Opacity: {
        auto maybe_opacity = layout_node.computed_values().opacity();
        if (!maybe_opacity.has_value())
            return {};
        return NumericStyleValue::create(maybe_opacity.release_value());
    }
    case CSS::PropertyID::JustifyContent:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().justify_content()));
    case CSS::PropertyID::BoxShadow: {
        auto maybe_box_shadow = layout_node.computed_values().box_shadow();
        if (!maybe_box_shadow.has_value())
            return {};
        auto box_shadow_data = maybe_box_shadow.release_value();
        return BoxShadowStyleValue::create(box_shadow_data.offset_x, box_shadow_data.offset_y, box_shadow_data.blur_radius, box_shadow_data.color);
    }
    case CSS::PropertyID::Width:
        return LengthStyleValue::create(layout_node.computed_values().width());
    case CSS::PropertyID::MinWidth:
        if (layout_node.computed_values().min_width().is_undefined())
            return IdentifierStyleValue::create(CSS::ValueID::None);
        return LengthStyleValue::create(layout_node.computed_values().min_width());
    case CSS::PropertyID::MaxWidth:
        if (layout_node.computed_values().max_width().is_undefined())
            return IdentifierStyleValue::create(CSS::ValueID::None);
        return LengthStyleValue::create(layout_node.computed_values().max_width());
    case CSS::PropertyID::Height:
        return LengthStyleValue::create(layout_node.computed_values().height());
    case CSS::PropertyID::MinHeight:
        if (layout_node.computed_values().min_height().is_undefined())
            return IdentifierStyleValue::create(CSS::ValueID::None);
        return LengthStyleValue::create(layout_node.computed_values().min_height());
    case CSS::PropertyID::MaxHeight:
        if (layout_node.computed_values().max_height().is_undefined())
            return IdentifierStyleValue::create(CSS::ValueID::None);
        return LengthStyleValue::create(layout_node.computed_values().max_height());
    case CSS::PropertyID::MarginTop:
        return LengthStyleValue::create(layout_node.computed_values().margin().top);
    case CSS::PropertyID::MarginRight:
        return LengthStyleValue::create(layout_node.computed_values().margin().right);
    case CSS::PropertyID::MarginBottom:
        return LengthStyleValue::create(layout_node.computed_values().margin().bottom);
    case CSS::PropertyID::MarginLeft:
        return LengthStyleValue::create(layout_node.computed_values().margin().left);
    case CSS::PropertyID::PaddingTop:
        return LengthStyleValue::create(layout_node.computed_values().padding().top);
    case CSS::PropertyID::PaddingRight:
        return LengthStyleValue::create(layout_node.computed_values().padding().right);
    case CSS::PropertyID::PaddingBottom:
        return LengthStyleValue::create(layout_node.computed_values().padding().bottom);
    case CSS::PropertyID::PaddingLeft:
        return LengthStyleValue::create(layout_node.computed_values().padding().left);
    case CSS::PropertyID::BorderRadius: {
        auto maybe_top_left_radius = property(CSS::PropertyID::BorderTopLeftRadius);
        auto maybe_top_right_radius = property(CSS::PropertyID::BorderTopRightRadius);
        auto maybe_bottom_left_radius = property(CSS::PropertyID::BorderBottomLeftRadius);
        auto maybe_bottom_right_radius = property(CSS::PropertyID::BorderBottomRightRadius);
        RefPtr<BorderRadiusStyleValue> top_left_radius, top_right_radius, bottom_left_radius, bottom_right_radius;
        if (maybe_top_left_radius.has_value()) {
            VERIFY(maybe_top_left_radius.value().value->is_border_radius());
            top_left_radius = maybe_top_left_radius.value().value->as_border_radius();
        }
        if (maybe_top_right_radius.has_value()) {
            VERIFY(maybe_top_right_radius.value().value->is_border_radius());
            top_right_radius = maybe_top_right_radius.value().value->as_border_radius();
        }
        if (maybe_bottom_left_radius.has_value()) {
            VERIFY(maybe_bottom_left_radius.value().value->is_border_radius());
            bottom_left_radius = maybe_bottom_left_radius.value().value->as_border_radius();
        }
        if (maybe_bottom_right_radius.has_value()) {
            VERIFY(maybe_bottom_right_radius.value().value->is_border_radius());
            bottom_right_radius = maybe_bottom_right_radius.value().value->as_border_radius();
        }

        return CombinedBorderRadiusStyleValue::create(top_left_radius.release_nonnull(), top_right_radius.release_nonnull(), bottom_right_radius.release_nonnull(), bottom_left_radius.release_nonnull());
    }
    // FIXME: The two radius components are not yet stored, as we currently don't actually render them.
    case CSS::PropertyID::BorderBottomLeftRadius:
        return BorderRadiusStyleValue::create(layout_node.computed_values().border_bottom_left_radius(), layout_node.computed_values().border_bottom_left_radius());
    case CSS::PropertyID::BorderBottomRightRadius:
        return BorderRadiusStyleValue::create(layout_node.computed_values().border_bottom_right_radius(), layout_node.computed_values().border_bottom_right_radius());
    case CSS::PropertyID::BorderTopLeftRadius:
        return BorderRadiusStyleValue::create(layout_node.computed_values().border_top_left_radius(), layout_node.computed_values().border_top_left_radius());
    case CSS::PropertyID::BorderTopRightRadius:
        return BorderRadiusStyleValue::create(layout_node.computed_values().border_top_right_radius(), layout_node.computed_values().border_top_right_radius());
    case CSS::PropertyID::OverflowX:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_x()));
    case CSS::PropertyID::OverflowY:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().overflow_y()));
    case CSS::PropertyID::Color:
        return ColorStyleValue::create(layout_node.computed_values().color());
    case PropertyID::BackgroundColor:
        return ColorStyleValue::create(layout_node.computed_values().background_color());
    case CSS::PropertyID::BackgroundRepeatX:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().background_repeat_x()));
    case CSS::PropertyID::BackgroundRepeatY:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().background_repeat_y()));
    case CSS::PropertyID::BackgroundRepeat: {
        auto maybe_background_repeat_x = property(CSS::PropertyID::BackgroundRepeatX);
        auto maybe_background_repeat_y = property(CSS::PropertyID::BackgroundRepeatY);
        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)));
    }
    case CSS::PropertyID::Background: {
        auto maybe_background_color = property(CSS::PropertyID::BackgroundColor);
        auto maybe_background_image = property(CSS::PropertyID::BackgroundImage);
        auto maybe_background_repeat_x = property(CSS::PropertyID::BackgroundRepeatX);
        auto maybe_background_repeat_y = property(CSS::PropertyID::BackgroundRepeatY);

        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)));
    }
    case CSS::PropertyID::ListStyleType:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().list_style_type()));
    case CSS::PropertyID::BoxSizing:
        return IdentifierStyleValue::create(to_css_value_id(layout_node.computed_values().box_sizing()));
    case CSS::PropertyID::Invalid:
        return IdentifierStyleValue::create(CSS::ValueID::Invalid);
    case CSS::PropertyID::Custom:
        dbgln("Computed style for custom properties was requested (?)");
        return {};
    default:
        dbgln("FIXME: Computed style for the '{}' property was requested", string_from_property_id(property_id));
        return {};
    }
    }
}

Optional<StyleProperty> ResolvedCSSStyleDeclaration::property(PropertyID property_id) const
{
    const_cast<DOM::Document&>(m_element->document()).ensure_layout();

    if (!m_element->layout_node()) {
        auto style = m_element->document().style_computer().compute_style(const_cast<DOM::Element&>(*m_element));
        if (auto maybe_property = style->property(property_id); maybe_property.has_value()) {
            return StyleProperty {
                .property_id = property_id,
                .value = maybe_property.release_value(),
            };
        }
        return {};
    }

    auto& layout_node = *m_element->layout_node();
    auto value = style_value_for_property(layout_node, property_id);
    if (!value)
        return {};
    return StyleProperty {
        .property_id = property_id,
        .value = value.release_nonnull(),
    };
}

bool ResolvedCSSStyleDeclaration::set_property(PropertyID, StringView)
{
    return false;
}

String ResolvedCSSStyleDeclaration::serialized() const
{
    // https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-csstext
    // If the computed flag is set, then return the empty string.

    // NOTE: ResolvedCSSStyleDeclaration is something you would only get from window.getComputedStyle(),
    //       which returns what the spec calls "resolved style". The "computed flag" is always set here.
    return String::empty();
}

}