Skip to content

Commit e064fa1

Browse files
Psychpsyogmta
authored andcommitted
LibWeb: Add transform-style and have it make a stacking context
1 parent c80b698 commit e064fa1

File tree

13 files changed

+89
-3
lines changed

13 files changed

+89
-3
lines changed

Libraries/LibWeb/CSS/ComputedProperties.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,12 @@ TransformOrigin ComputedProperties::transform_origin() const
756756
return { x_value, y_value, z_value };
757757
}
758758

759+
TransformStyle ComputedProperties::transform_style() const
760+
{
761+
auto const& value = property(PropertyID::TransformStyle);
762+
return keyword_to_transform_style(value.to_keyword()).release_value();
763+
}
764+
759765
Optional<Color> ComputedProperties::accent_color(Layout::NodeWithStyle const& node) const
760766
{
761767
auto const& value = property(PropertyID::AccentColor);

Libraries/LibWeb/CSS/ComputedProperties.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ class WEB_API ComputedProperties final : public JS::Cell {
207207
Vector<Transformation> transformations() const;
208208
TransformBox transform_box() const;
209209
TransformOrigin transform_origin() const;
210+
TransformStyle transform_style() const;
210211
Optional<Transformation> rotate() const;
211212
Optional<Transformation> translate() const;
212213
Optional<Transformation> scale() const;

Libraries/LibWeb/CSS/ComputedValues.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ class InitialValues {
240240
static TableLayout table_layout() { return TableLayout::Auto; }
241241
static QuotesData quotes() { return QuotesData { .type = QuotesData::Type::Auto }; }
242242
static TransformBox transform_box() { return TransformBox::ViewBox; }
243+
static TransformStyle transform_style() { return TransformStyle::Flat; }
243244
static Direction direction() { return Direction::Ltr; }
244245
static UnicodeBidi unicode_bidi() { return UnicodeBidi::Normal; }
245246
static WritingMode writing_mode() { return WritingMode::HorizontalTb; }
@@ -634,6 +635,7 @@ class ComputedValues {
634635
Vector<Transformation> const& transformations() const { return m_noninherited.transformations; }
635636
TransformBox const& transform_box() const { return m_noninherited.transform_box; }
636637
TransformOrigin const& transform_origin() const { return m_noninherited.transform_origin; }
638+
TransformStyle const& transform_style() const { return m_noninherited.transform_style; }
637639
Optional<Transformation> const& rotate() const { return m_noninherited.rotate; }
638640
Optional<Transformation> const& translate() const { return m_noninherited.translate; }
639641
Optional<Transformation> const& scale() const { return m_noninherited.scale; }
@@ -797,6 +799,7 @@ class ComputedValues {
797799
Vector<Transformation> transformations {};
798800
TransformBox transform_box { InitialValues::transform_box() };
799801
TransformOrigin transform_origin {};
802+
TransformStyle transform_style { InitialValues::transform_style() };
800803
BoxSizing box_sizing { InitialValues::box_sizing() };
801804
ContentData content;
802805
Variant<VerticalAlign, LengthPercentage> vertical_align { InitialValues::vertical_align() };
@@ -996,6 +999,7 @@ class MutableComputedValues final : public ComputedValues {
996999
void set_transformations(Vector<Transformation> value) { m_noninherited.transformations = move(value); }
9971000
void set_transform_box(TransformBox value) { m_noninherited.transform_box = value; }
9981001
void set_transform_origin(TransformOrigin value) { m_noninherited.transform_origin = move(value); }
1002+
void set_transform_style(TransformStyle value) { m_noninherited.transform_style = value; }
9991003
void set_translate(Transformation value) { m_noninherited.translate = move(value); }
10001004
void set_box_sizing(BoxSizing value) { m_noninherited.box_sizing = value; }
10011005
void set_vertical_align(Variant<VerticalAlign, LengthPercentage> value) { m_noninherited.vertical_align = move(value); }

Libraries/LibWeb/CSS/Enums.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,11 @@
844844
"border-box",
845845
"fill-box",
846846
"stroke-box",
847-
"view-box "
847+
"view-box"
848+
],
849+
"transform-style": [
850+
"flat",
851+
"preserve-3d"
848852
],
849853
"transition-behavior": [
850854
"normal",

Libraries/LibWeb/CSS/Keywords.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@
216216
"fill-box",
217217
"fine",
218218
"fixed",
219+
"flat",
219220
"flex",
220221
"flex-end",
221222
"flex-start",
@@ -424,6 +425,7 @@
424425
"pre-line",
425426
"pre-wrap",
426427
"preserve",
428+
"preserve-3d",
427429
"preserve-breaks",
428430
"preserve-spaces",
429431
"pretty",

Libraries/LibWeb/CSS/Properties.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3847,6 +3847,15 @@
38473847
],
38483848
"percentages-resolve-to": "length"
38493849
},
3850+
"transform-style": {
3851+
"animation-type": "discrete",
3852+
"inherited": false,
3853+
"initial": "flat",
3854+
"valid-identifiers": [
3855+
"flat",
3856+
"preserve-3d"
3857+
]
3858+
},
38503859
"transition": {
38513860
"affects-layout": false,
38523861
"inherited": false,

Libraries/LibWeb/Layout/Node.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,13 @@ bool Node::establishes_stacking_context() const
295295
if (computed_values.perspective().has_value() || will_change_property(CSS::PropertyID::Perspective))
296296
return true;
297297

298+
// https://drafts.csswg.org/css-transforms-2/#transform-style-property
299+
// A computed value of 'preserve-3d' for 'transform-style' on a transformable element establishes both a
300+
// stacking context and a containing block for all descendants.
301+
// FIXME: Check that the element is a transformable element.
302+
if (computed_values.transform_style() == CSS::TransformStyle::Preserve3d || will_change_property(CSS::PropertyID::TransformStyle))
303+
return true;
304+
298305
return computed_values.opacity() < 1.0f || will_change_property(CSS::PropertyID::Opacity);
299306
}
300307

@@ -694,6 +701,7 @@ void NodeWithStyle::apply_style(CSS::ComputedProperties const& computed_style)
694701
computed_values.set_transform_box(computed_style.transform_box());
695702
computed_values.set_transform_origin(computed_style.transform_origin());
696703
computed_values.set_perspective(computed_style.perspective());
704+
computed_values.set_transform_style(computed_style.transform_style());
697705

698706
auto const& transition_delay_property = computed_style.property(CSS::PropertyID::TransitionDelay);
699707
if (transition_delay_property.is_time()) {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>CSS Reftest Reference</title>
5+
<link rel="author" title="Aryeh Gregor" href="mailto:ayg@aryeh.name">
6+
<style>
7+
div {
8+
height: 100px;
9+
width: 100px;
10+
background: lime;
11+
}
12+
</style>
13+
</head>
14+
<body>
15+
<div></div>
16+
</body>
17+
</html>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE HTML>
2+
<title>'transform-style: preserve-3d' establishes a stacking context.</title>
3+
<link rel="author" title="Psychpsyo" href="mailto:psychpsyo@gmail.com">
4+
<link rel="help" href="https://drafts.csswg.org/css-transforms-2/#transform-style-property">
5+
<link rel="match" href="../../../../expected/wpt-import/css/css-transforms/transform-lime-square-ref.html">
6+
<style>
7+
div {
8+
width: 100px;
9+
height: 100px;
10+
}
11+
#front {
12+
background-color: lime;
13+
/* makes a stacking context and puts this on top */
14+
position: absolute;
15+
z-index: 10;
16+
}
17+
#back {
18+
transform-style: preserve-3d;
19+
}
20+
#notOnTop {
21+
background-color: red;
22+
/* z-index is higher than on #front, but this should still be covered up because it is inside #back, which has 'transform-style: preserve-3d' */
23+
position: absolute;
24+
z-index: 1000;
25+
}
26+
</style>
27+
<div id="front"></div>
28+
<div id="back">
29+
<div id="notOnTop"></div>
30+
</div>

Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ All properties associated with getComputedStyle(document.body):
276276
"transform",
277277
"transform-box",
278278
"transform-origin",
279+
"transform-style",
279280
"transition-behavior",
280281
"transition-delay",
281282
"transition-duration",

0 commit comments

Comments
 (0)