Skip to content

Commit 6b5bdea

Browse files
authored
fix(builtin_scene): make background-position function correctly (#331)
1 parent 86c4af7 commit 6b5bdea

4 files changed

Lines changed: 437 additions & 2 deletions

File tree

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Background Position Bottom/Right Alignment Test</title>
7+
<style>
8+
body {
9+
margin: 0;
10+
padding: 20px;
11+
font-family: Arial, sans-serif;
12+
background-color: #fff;
13+
}
14+
15+
.test-container {
16+
margin: 20px 0;
17+
padding: 10px;
18+
border: 1px solid #ccc;
19+
background-color: #f5f5f5;
20+
}
21+
22+
h1 {
23+
color: #333;
24+
font-size: 24px;
25+
margin-bottom: 20px;
26+
}
27+
28+
h2 {
29+
color: #666;
30+
font-size: 18px;
31+
margin: 15px 0 10px 0;
32+
}
33+
34+
.test-box {
35+
width: 200px;
36+
height: 150px;
37+
border: 2px solid #333;
38+
background-image: url(https://ar.rokidcdn.com/web-assets/yodaos-jsar/dist/images/a.jpg);
39+
background-size: 50px 50px;
40+
background-repeat: no-repeat;
41+
margin: 10px;
42+
position: relative;
43+
}
44+
45+
.test-box::after {
46+
content: '';
47+
position: absolute;
48+
top: 0;
49+
left: 0;
50+
right: 0;
51+
bottom: 0;
52+
border: 1px dashed red;
53+
pointer-events: none;
54+
}
55+
56+
/* Test cases that should align to bottom-right */
57+
.bg-position-right-bottom-keywords {
58+
background-position: right bottom;
59+
}
60+
61+
.bg-position-100-percent {
62+
background-position: 100% 100%;
63+
}
64+
65+
.bg-position-right-100-percent {
66+
background-position: right 100%;
67+
}
68+
69+
.bg-position-100-bottom {
70+
background-position: 100% bottom;
71+
}
72+
73+
/* Test cases that should align to bottom-left */
74+
.bg-position-left-bottom {
75+
background-position: left bottom;
76+
}
77+
78+
.bg-position-0-100-percent {
79+
background-position: 0% 100%;
80+
}
81+
82+
/* Test cases that should align to top-right */
83+
.bg-position-right-top {
84+
background-position: right top;
85+
}
86+
87+
.bg-position-100-0-percent {
88+
background-position: 100% 0%;
89+
}
90+
91+
.test-row {
92+
display: flex;
93+
flex-wrap: wrap;
94+
gap: 10px;
95+
margin-bottom: 20px;
96+
}
97+
98+
.test-description {
99+
font-size: 12px;
100+
color: #666;
101+
text-align: center;
102+
margin-top: 5px;
103+
width: 200px;
104+
}
105+
106+
.expected {
107+
font-weight: bold;
108+
color: #007700;
109+
}
110+
</style>
111+
</head>
112+
113+
<body>
114+
<h1>CSS Background Position Bottom/Right Alignment Test</h1>
115+
116+
<div class="test-container">
117+
<h2>Bottom-Right Alignment Tests (Image should be in bottom-right corner)</h2>
118+
<p>All these tests should position the 50x50px background image in the bottom-right corner of each 200x150px box:</p>
119+
<div class="test-row">
120+
<div>
121+
<div class="test-box bg-position-right-bottom-keywords"></div>
122+
<div class="test-description">
123+
background-position: right bottom<br>
124+
<span class="expected">Expected: bottom-right corner</span>
125+
</div>
126+
</div>
127+
<div>
128+
<div class="test-box bg-position-100-percent"></div>
129+
<div class="test-description">
130+
background-position: 100% 100%<br>
131+
<span class="expected">Expected: bottom-right corner</span>
132+
</div>
133+
</div>
134+
<div>
135+
<div class="test-box bg-position-right-100-percent"></div>
136+
<div class="test-description">
137+
background-position: right 100%<br>
138+
<span class="expected">Expected: bottom-right corner</span>
139+
</div>
140+
</div>
141+
<div>
142+
<div class="test-box bg-position-100-bottom"></div>
143+
<div class="test-description">
144+
background-position: 100% bottom<br>
145+
<span class="expected">Expected: bottom-right corner</span>
146+
</div>
147+
</div>
148+
</div>
149+
</div>
150+
151+
<div class="test-container">
152+
<h2>Other Corner Alignment Tests</h2>
153+
<p>These tests verify other corner positions work correctly:</p>
154+
<div class="test-row">
155+
<div>
156+
<div class="test-box bg-position-left-bottom"></div>
157+
<div class="test-description">
158+
background-position: left bottom<br>
159+
<span class="expected">Expected: bottom-left corner</span>
160+
</div>
161+
</div>
162+
<div>
163+
<div class="test-box bg-position-0-100-percent"></div>
164+
<div class="test-description">
165+
background-position: 0% 100%<br>
166+
<span class="expected">Expected: bottom-left corner</span>
167+
</div>
168+
</div>
169+
<div>
170+
<div class="test-box bg-position-right-top"></div>
171+
<div class="test-description">
172+
background-position: right top<br>
173+
<span class="expected">Expected: top-right corner</span>
174+
</div>
175+
</div>
176+
<div>
177+
<div class="test-box bg-position-100-0-percent"></div>
178+
<div class="test-description">
179+
background-position: 100% 0%<br>
180+
<span class="expected">Expected: top-right corner</span>
181+
</div>
182+
</div>
183+
</div>
184+
</div>
185+
186+
<div class="test-container">
187+
<h2>Expected Results</h2>
188+
<p>According to CSS specification:</p>
189+
<ul>
190+
<li><strong>right bottom</strong> and <strong>100% 100%</strong> should be identical - both place image in bottom-right corner</li>
191+
<li><strong>left bottom</strong> and <strong>0% 100%</strong> should be identical - both place image in bottom-left corner</li>
192+
<li><strong>right top</strong> and <strong>100% 0%</strong> should be identical - both place image in top-right corner</li>
193+
<li>Images should be flush with the edges (no gaps or offsets)</li>
194+
</ul>
195+
<p>If the implementation is incorrect, percentage values may not align properly with keyword values.</p>
196+
197+
<h3>Implementation Notes</h3>
198+
<p>The fix handles cases where "100% 100%" is parsed as two length values instead of percentages.
199+
Common percentage values (0%, 25%, 50%, 75%, 100%) are detected and processed correctly to ensure
200+
proper edge alignment according to CSS Background and Borders Module Level 3 specification.</p>
201+
</div>
202+
</body>
203+
204+
</html>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Background Position Fix Demo</title>
6+
<style>
7+
body {
8+
margin: 20px;
9+
font-family: Arial, sans-serif;
10+
}
11+
12+
.demo-container {
13+
display: flex;
14+
gap: 20px;
15+
margin: 20px 0;
16+
}
17+
18+
.test-box {
19+
width: 150px;
20+
height: 100px;
21+
border: 2px solid #333;
22+
background: linear-gradient(45deg, #ff6b6b 0%, #4ecdc4 50%, #ffe66d 100%);
23+
background-size: 30px 30px;
24+
background-repeat: no-repeat;
25+
position: relative;
26+
}
27+
28+
.test-box::after {
29+
content: '';
30+
position: absolute;
31+
top: 0;
32+
left: 0;
33+
right: 0;
34+
bottom: 0;
35+
border: 1px dashed red;
36+
pointer-events: none;
37+
}
38+
39+
.bottom-right-keywords {
40+
background-position: right bottom;
41+
}
42+
43+
.bottom-right-percent {
44+
background-position: 100% 100%;
45+
}
46+
47+
.top-right-percent {
48+
background-position: 100% 0%;
49+
}
50+
51+
.bottom-left-percent {
52+
background-position: 0% 100%;
53+
}
54+
55+
.description {
56+
text-align: center;
57+
font-size: 12px;
58+
margin-top: 5px;
59+
color: #666;
60+
}
61+
62+
.success {
63+
color: #007700;
64+
font-weight: bold;
65+
}
66+
</style>
67+
</head>
68+
<body>
69+
<h1>Background Position Bottom/Right Alignment Fix</h1>
70+
71+
<p>This demonstrates the fix for background-position alignment. Each box shows a 30x30px gradient positioned in different corners of a 150x100px container.</p>
72+
73+
<div class="demo-container">
74+
<div>
75+
<div class="test-box bottom-right-keywords"></div>
76+
<div class="description">
77+
<code>background-position: right bottom;</code><br>
78+
<span class="success">✓ Bottom-right corner</span>
79+
</div>
80+
</div>
81+
82+
<div>
83+
<div class="test-box bottom-right-percent"></div>
84+
<div class="description">
85+
<code>background-position: 100% 100%;</code><br>
86+
<span class="success">✓ Should match right bottom</span>
87+
</div>
88+
</div>
89+
90+
<div>
91+
<div class="test-box top-right-percent"></div>
92+
<div class="description">
93+
<code>background-position: 100% 0%;</code><br>
94+
<span class="success">✓ Top-right corner</span>
95+
</div>
96+
</div>
97+
98+
<div>
99+
<div class="test-box bottom-left-percent"></div>
100+
<div class="description">
101+
<code>background-position: 0% 100%;</code><br>
102+
<span class="success">✓ Bottom-left corner</span>
103+
</div>
104+
</div>
105+
</div>
106+
107+
<h2>Fix Summary</h2>
108+
<p><strong>Issue:</strong> Background images with percentage positions (like <code>100% 100%</code>) were not aligning flush with element edges.</p>
109+
<p><strong>Solution:</strong> Enhanced the <code>calculateBackgroundPosition</code> function to properly detect and handle percentage values in two-value background-position syntax.</p>
110+
<p><strong>Result:</strong> Perfect edge alignment matching CSS specification behavior.</p>
111+
</body>
112+
</html>

0 commit comments

Comments
 (0)