File: current-time-writing-modes.html

package info (click to toggle)
firefox-esr 68.10.0esr-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,143,932 kB
  • sloc: cpp: 5,227,879; javascript: 4,315,531; ansic: 2,467,042; python: 794,975; java: 349,993; asm: 232,034; xml: 228,320; sh: 82,008; lisp: 41,202; makefile: 22,347; perl: 15,555; objc: 5,277; cs: 4,725; yacc: 1,778; ada: 1,681; pascal: 1,673; lex: 1,417; exp: 527; php: 436; ruby: 225; awk: 162; sed: 53; csh: 44
file content (402 lines) | stat: -rw-r--r-- 16,351 bytes parent folder | download | duplicates (2)
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>ScrollTimeline current time algorithm - interaction with writing modes</title>
<link rel="help" href="https://wicg.github.io/scroll-animations/#current-time-algorithm">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>

<script src="./resources/scrolltimeline-utils.js"></script>

<body></body>

<script>
'use strict';

test(function() {
  const scrollerOverrides = new Map([['direction', 'rtl']]);
  const scroller = setupScrollTimelineTest(scrollerOverrides);

  // Set the timeRange such that currentTime maps directly to the value
  // scrolled. The contents and scroller are square, so it suffices to compute
  // one edge and use it for all the timelines.
  const scrollerSize = scroller.scrollHeight - scroller.clientHeight;

  const blockScrollTimeline = new ScrollTimeline(
      {scrollSource: scroller, timeRange: scrollerSize, orientation: 'block'});
  const inlineScrollTimeline = new ScrollTimeline(
      {scrollSource: scroller, timeRange: scrollerSize, orientation: 'inline'});
  const horizontalScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal'
  });
  const verticalScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'vertical'
  });

  // Unscrolled, all timelines should read a current time of 0 even though the
  // X-axis will have started at the right hand side for rtl.
  assert_equals(
      blockScrollTimeline.currentTime, 0, 'Unscrolled block timeline');
  assert_equals(
      inlineScrollTimeline.currentTime, 0, 'Unscrolled inline timeline');
  assert_equals(
      horizontalScrollTimeline.currentTime, 0,
      'Unscrolled horizontal timeline');
  assert_equals(
      verticalScrollTimeline.currentTime, 0, 'Unscrolled vertical timeline');

  // The offset in the inline/horizontal direction should be inverted. The
  // block/vertical direction should be unaffected.
  scroller.scrollTop = 50;
  scroller.scrollLeft = 75;

  assert_equals(blockScrollTimeline.currentTime, 50, 'Scrolled block timeline');
  assert_equals(
      inlineScrollTimeline.currentTime, scrollerSize - 75,
      'Scrolled inline timeline');
  assert_equals(
      horizontalScrollTimeline.currentTime, scrollerSize - 75,
      'Scrolled horizontal timeline');
  assert_equals(
      verticalScrollTimeline.currentTime, 50, 'Scrolled vertical timeline');
}, 'currentTime handles direction: rtl correctly');

test(function() {
  const scrollerOverrides = new Map([['writing-mode', 'vertical-rl']]);
  const scroller = setupScrollTimelineTest(scrollerOverrides);

  // Set the timeRange such that currentTime maps directly to the value
  // scrolled. The contents and scroller are square, so it suffices to compute
  // one edge and use it for all the timelines.
  const scrollerSize = scroller.scrollHeight - scroller.clientHeight;

  const blockScrollTimeline = new ScrollTimeline(
      {scrollSource: scroller, timeRange: scrollerSize, orientation: 'block'});
  const inlineScrollTimeline = new ScrollTimeline(
      {scrollSource: scroller, timeRange: scrollerSize, orientation: 'inline'});
  const horizontalScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal'
  });
  const verticalScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'vertical'
  });

  // Unscrolled, all timelines should read a current time of 0 even though the
  // X-axis will have started at the right hand side for vertical-rl.
  assert_equals(
      blockScrollTimeline.currentTime, 0, 'Unscrolled block timeline');
  assert_equals(
      inlineScrollTimeline.currentTime, 0, 'Unscrolled inline timeline');
  assert_equals(
      horizontalScrollTimeline.currentTime, 0,
      'Unscrolled horizontal timeline');
  assert_equals(
      verticalScrollTimeline.currentTime, 0, 'Unscrolled vertical timeline');

  // For vertical-rl, the X-axis starts on the right-hand-side and is the block
  // axis. The Y-axis is normal but is the inline axis. For the
  // horizontal/vertical cases, horizontal starts on the right-hand-side and
  // vertical is normal.
  scroller.scrollTop = 50;
  scroller.scrollLeft = 75;

  assert_equals(
      blockScrollTimeline.currentTime, scrollerSize - 75,
      'Scrolled block timeline');
  assert_equals(
      inlineScrollTimeline.currentTime, 50, 'SCrolled inline timeline');
  assert_equals(
      horizontalScrollTimeline.currentTime, scrollerSize - 75,
      'Scrolled horizontal timeline');
  assert_equals(
      verticalScrollTimeline.currentTime, 50, 'Scrolled vertical timeline');
}, 'currentTime handles writing-mode: vertical-rl correctly');

test(function() {
  const scrollerOverrides = new Map([['writing-mode', 'vertical-lr']]);
  const scroller = setupScrollTimelineTest(scrollerOverrides);

  // Set the timeRange such that currentTime maps directly to the value
  // scrolled. The contents and scroller are square, so it suffices to compute
  // one edge and use it for all the timelines.
  const scrollerSize = scroller.scrollHeight - scroller.clientHeight;

  const blockScrollTimeline = new ScrollTimeline(
      {scrollSource: scroller, timeRange: scrollerSize, orientation: 'block'});
  const inlineScrollTimeline = new ScrollTimeline(
      {scrollSource: scroller, timeRange: scrollerSize, orientation: 'inline'});
  const horizontalScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal'
  });
  const verticalScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'vertical'
  });

  // Unscrolled, all timelines should read a current time of 0.
  assert_equals(
      blockScrollTimeline.currentTime, 0, 'Unscrolled block timeline');
  assert_equals(
      inlineScrollTimeline.currentTime, 0, 'Unscrolled inline timeline');
  assert_equals(
      horizontalScrollTimeline.currentTime, 0,
      'Unscrolled horizontal timeline');
  assert_equals(
      verticalScrollTimeline.currentTime, 0, 'Unscrolled vertical timeline');

  // For vertical-lr, both axes start at their 'normal' positions but the X-axis
  // is the block direction and the Y-axis is the inline direction. This does
  // not affect horizontal/vertical.
  scroller.scrollTop = 50;
  scroller.scrollLeft = 75;

  assert_equals(blockScrollTimeline.currentTime, 75, 'Scrolled block timeline');
  assert_equals(
      inlineScrollTimeline.currentTime, 50, 'Scrolled inline timeline');
  assert_equals(
      horizontalScrollTimeline.currentTime, 75, 'Scrolled horizontal timeline');
  assert_equals(
      verticalScrollTimeline.currentTime, 50, 'Scrolled vertical timeline');
}, 'currentTime handles writing-mode: vertical-lr correctly');

test(function() {
  const scrollerOverrides = new Map([['direction', 'rtl']]);
  const scroller = setupScrollTimelineTest(scrollerOverrides);
  // Set the timeRange such that currentTime maps directly to the value
  // scrolled. The contents and scroller are square, so it suffices to compute
  // one edge and use it for all the timelines.
  const scrollerSize = scroller.scrollHeight - scroller.clientHeight;

  const lengthScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal',
    startScrollOffset: '20px'
  });
  const percentageScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal',
    startScrollOffset: '20%'
  });
  const calcScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal',
    startScrollOffset: 'calc(20% - 5px)'
  });

  // Unscrolled, all timelines should read a current time of unresolved, since
  // the current offset (0) will be less than the startScrollOffset.
  assert_equals(
      lengthScrollTimeline.currentTime, null,
      'Unscrolled length-based timeline');
  assert_equals(
      percentageScrollTimeline.currentTime, null,
      'Unscrolled percentage-based timeline');
  assert_equals(
      calcScrollTimeline.currentTime, null, 'Unscrolled calc-based timeline');

  // With direction rtl offsets are inverted, such that scrollLeft ==
  // scrollerSize is the 'zero' point for currentTime. However the
  // startScrollOffset is an absolute distance along the offset, so doesn't
  // need adjusting.

  // Check the length-based ScrollTimeline.
  scroller.scrollLeft = scrollerSize;
  assert_equals(
      lengthScrollTimeline.currentTime, null,
      'Length-based timeline before the startScrollOffset point');
  scroller.scrollLeft = scrollerSize - 20;
  assert_equals(
      lengthScrollTimeline.currentTime, 0,
      'Length-based timeline at the startScrollOffset point');
  scroller.scrollLeft = scrollerSize - 50;
  assert_equals(
      lengthScrollTimeline.currentTime,
      calculateCurrentTime(50, 20, scrollerSize, scrollerSize),
      'Length-based timeline after the startScrollOffset point');

  // Check the percentage-based ScrollTimeline.
  scroller.scrollLeft = scrollerSize - (0.19 * scrollerSize);
  assert_equals(
      percentageScrollTimeline.currentTime, null,
      'Percentage-based timeline before the startScrollOffset point');
  scroller.scrollLeft = scrollerSize - (0.20 * scrollerSize);
  assert_equals(
      percentageScrollTimeline.currentTime, 0,
      'Percentage-based timeline at the startScrollOffset point');
  scroller.scrollLeft = scrollerSize - (0.4 * scrollerSize);
  assert_equals(
      percentageScrollTimeline.currentTime,
      calculateCurrentTime(
          0.4 * scrollerSize, 0.2 * scrollerSize, scrollerSize, scrollerSize),
      'Percentage-based timeline after the startScrollOffset point');

  // Check the calc-based ScrollTimeline.
  scroller.scrollLeft = scrollerSize - (0.2 * scrollerSize - 10);
  assert_equals(
      calcScrollTimeline.currentTime, null,
      'Calc-based timeline before the startScrollOffset point');
  scroller.scrollLeft = scrollerSize - (0.2 * scrollerSize - 5);
  assert_equals(
      calcScrollTimeline.currentTime, 0,
      'Calc-based timeline at the startScrollOffset point');
  scroller.scrollLeft = scrollerSize - (0.2 * scrollerSize);
  assert_equals(
      calcScrollTimeline.currentTime,
      calculateCurrentTime(
          0.2 * scrollerSize, 0.2 * scrollerSize - 5, scrollerSize,
          scrollerSize),
      'Calc-based timeline after the startScrollOffset point');
}, 'currentTime handles startScrollOffset with direction: rtl correctly');

test(function() {
  const scrollerOverrides = new Map([['direction', 'rtl']]);
  const scroller = setupScrollTimelineTest(scrollerOverrides);
  // Set the timeRange such that currentTime maps directly to the value
  // scrolled. The contents and scroller are square, so it suffices to compute
  // one edge and use it for all the timelines.
  const scrollerSize = scroller.scrollHeight - scroller.clientHeight;

  const lengthScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal',
    endScrollOffset: (scrollerSize - 20) + 'px'
  });
  const percentageScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal',
    endScrollOffset: '80%'
  });
  const calcScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'horizontal',
    endScrollOffset: 'calc(80% + 5px)'
  });

  // With direction rtl offsets are inverted, such that scrollLeft ==
  // scrollerSize is the 'zero' point for currentTime. However the
  // endScrollOffset is an absolute distance along the offset, so doesn't need
  // adjusting.

  // Check the length-based ScrollTimeline.
  scroller.scrollLeft = 0;
  assert_equals(
      lengthScrollTimeline.currentTime, null,
      'Length-based timeline after the endScrollOffset point');
  scroller.scrollLeft = 20;
  assert_equals(
      lengthScrollTimeline.currentTime, null,
      'Length-based timeline at the endScrollOffset point');
  scroller.scrollLeft = 50;
  assert_equals(
      lengthScrollTimeline.currentTime,
      calculateCurrentTime(
          scrollerSize - 50, 0, scrollerSize - 20, scrollerSize),
      'Length-based timeline before the endScrollOffset point');

  // Check the percentage-based ScrollTimeline.
  scroller.scrollLeft = 0.19 * scrollerSize;
  assert_equals(
      percentageScrollTimeline.currentTime, null,
      'Percentage-based timeline after the endScrollOffset point');
  scroller.scrollLeft = 0.20 * scrollerSize;
  assert_equals(
      percentageScrollTimeline.currentTime, null,
      'Percentage-based timeline at the endScrollOffset point');
  scroller.scrollLeft = 0.4 * scrollerSize;
  assert_equals(
      percentageScrollTimeline.currentTime,
      calculateCurrentTime(
          0.6 * scrollerSize, 0, 0.8 * scrollerSize, scrollerSize),
      'Percentage-based timeline before the endScrollOffset point');

  // Check the calc-based ScrollTimeline. 80% + 5px
  scroller.scrollLeft = 0.2 * scrollerSize - 10;
  assert_equals(
      calcScrollTimeline.currentTime, null,
      'Calc-based timeline after the endScrollOffset point');
  scroller.scrollLeft = 0.2 * scrollerSize - 5;
  assert_equals(
      calcScrollTimeline.currentTime, null,
      'Calc-based timeline at the endScrollOffset point');
  scroller.scrollLeft = 0.2 * scrollerSize;
  assert_equals(
      calcScrollTimeline.currentTime,
      calculateCurrentTime(
          0.8 * scrollerSize, 0, 0.8 * scrollerSize + 5, scrollerSize),
      'Calc-based timeline before the endScrollOffset point');
}, 'currentTime handles endScrollOffset with direction: rtl correctly');

test(function() {
  const scrollerOverrides = new Map([['direction', 'rtl']]);
  const scroller = setupScrollTimelineTest(scrollerOverrides);
  // Set the timeRange such that currentTime maps directly to the value
  // scrolled. The contents and scroller are square, so it suffices to compute
  // one edge and use it for all the timelines.
  const scrollerSize = scroller.scrollHeight - scroller.clientHeight;

  // When the endScrollOffset is equal to the maximum scroll offset (and there
  // are no fill modes), the endScrollOffset is treated as inclusive.
  const inclusiveAutoScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'block',
    endScrollOffset: 'auto'
  });
  const inclusiveLengthScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'block',
    endScrollOffset: scrollerSize + 'px'
  });
  const inclusivePercentageScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'block',
    endScrollOffset: '100%'
  });
  const inclusiveCalcScrollTimeline = new ScrollTimeline({
    scrollSource: scroller,
    timeRange: scrollerSize,
    orientation: 'block',
    endScrollOffset: 'calc(80% + ' + (0.2 * scrollerSize) + 'px)'
  });

  // With direction rtl offsets are inverted, such that scrollLeft ==
  // scrollerSize is the 'zero' point for currentTime. However the
  // endScrollOffset is an absolute distance along the offset, so doesn't need
  // adjusting.

  scroller.scrollLeft = 0;
  let expectedCurrentTime = calculateCurrentTime(
      scroller.scrollLeft, 0, scrollerSize, scrollerSize);

  assert_equals(
    inclusiveAutoScrollTimeline.currentTime, expectedCurrentTime,
    'Inclusive auto timeline at the endScrollOffset point');
  assert_equals(
    inclusiveLengthScrollTimeline.currentTime, expectedCurrentTime,
    'Inclusive length-based timeline at the endScrollOffset point');
  assert_equals(
    inclusivePercentageScrollTimeline.currentTime, expectedCurrentTime,
    'Inclusive percentage-based timeline at the endScrollOffset point');
  assert_equals(
    inclusiveCalcScrollTimeline.currentTime, expectedCurrentTime,
    'Inclusive calc-based timeline at the endScrollOffset point');
}, 'currentTime handles endScrollOffset (inclusive case) with direction: rtl correctly');
</script>