File: multi-range-user-select.html

package info (click to toggle)
firefox 147.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,683,324 kB
  • sloc: cpp: 7,607,156; javascript: 6,532,492; ansic: 3,775,158; python: 1,415,368; xml: 634,556; asm: 438,949; java: 186,241; sh: 62,751; makefile: 18,079; objc: 13,092; perl: 12,808; yacc: 4,583; cs: 3,846; pascal: 3,448; lex: 1,720; ruby: 1,003; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10; exp: 6
file content (416 lines) | stat: -rw-r--r-- 13,854 bytes parent folder | download
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
<!DOCTYPE HTML>
<html class="reftest-wait"><head>
    <meta charset="utf-8">
    <title>Testcase #1 for bug 1129078</title>
    <script src="/tests/SimpleTest/SimpleTest.js"></script>
    <script src="/tests/SimpleTest/EventUtils.js"></script>
    <script src="selection-utils.js"></script>

<style type="text/css">
@font-face {
  font-family: Ahem;
  src: url("Ahem.ttf");
}
html,body { margin:0; padding: 0; }
body,pre {
  font-family: Ahem;
  font-size: 20px;
}
span {
  user-select: none;
}
x {
  user-select: text;
}
</style>
</head>
<body>

<pre id="select">
2af45494-a<x>k7e-1</x><span id="span2">1e4-a0c6-a7e7
38222880-bj6d-11e4-8064-fb7b
3d649ae</span><x>4-ci5</x><span id="span3">c-11e4-995d-17b2
434351bc-dh4b-11e4-9971-4fc8
4dc0e0b4-eg4a-11e4-8c28-5319
a9631</span><x>9c8-ad7d-1</x>1e4-b312-039c
</pre>

<pre id="log" style="border:1px solid green"></pre>

<script>
window.info = parent.info;
window.is = parent.is;
window.isnot = parent.isnot;
window.ok = parent.ok;

const pre = document.getElementById("select");

var sel = window.getSelection();

function enableSelection(id) {
  var span = document.getElementById(id);
  span.style.MozUserSelect = 'text';
}

function setupPrevSelection() {
  dragSelectPoints(pre, 300, 125, 200, 5);
}

function setupNextSelection() {
  dragSelectPoints(pre, 199, 5, 300, 125);
}

var ops = {
  S_ : shiftClick,
  SA : shiftAccelClick,
  AD : accelDragSelect,
  SL : keyLeft,
  SR : keyRight
}

function runTest() {
  const excludeNonSelectableNodes = SpecialPowers.getBoolPref("dom.selection.exclude_non_selectable_nodes");

  const firstText = pre.childNodes[0];             // [0] 1st line:  0-9 (+ leading linefeed 1)
  const xBeforeSpan2 = firstText.nextSibling;      // [1] 1st line:  0-4
  const span2 = document.getElementById("span2");  // [2] 1st line:  0-13
                                                   //     2nd line: 14-42
                                                   //     3rd line: 43-49
  const xAfterSpan2 = span2.nextSibling;           // [3] 3rd line:  0-5
  const span3 = document.getElementById("span3");  // [4] 3rd line:  0-16
                                                   //     4th line: 17-43
                                                   //     5th line: 44-74
                                                   //     6th line: 75-79
  const xAfterSpan3 = span3.nextSibling;           // [5] 6th line:  0-9
  const lastText = xAfterSpan3.nextSibling;        // [6] 6th line:  0-12 (+ trailing linefeed 1)

  sel = window.getSelection();
  sel.removeAllRanges();
  document.body.offsetHeight;
  var hash = window.location.hash
  if (hash.substring(0,5)=="#prev")
    setupPrevSelection();
  else
    setupNextSelection();
  var op = hash.substring(6,8);
  var action = ops[op];
  var test = hash.substring(0,6);
  if (hash.substring(0,5) == "#prev") {
    if (test == "#prev1") {
      if (action == keyLeft) {
        keyLeft({shiftKey:true}, 2)
        checkRanges(
          excludeNonSelectableNodes
           ? [
               [firstText, 8, pre, 2],
               [xAfterSpan2, 0, pre, 4],
               [xAfterSpan3, 0, lastText, 0],
             ]
            : [[firstText, 8, lastText, 0]],
          {id: "prev1: after Shift+ArrowLeft twice"}
        );
      } else if (action == keyRight) {
        keyRight({shiftKey:true}, 2)
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [xBeforeSpan2.firstChild, 2, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, lastText, 0],
              ]
            : [[xBeforeSpan2.firstChild, 2, lastText, 0]],
          {id: "prev1: after Shift+ArrowRight twice"}
        );
      } else if (action == accelDragSelect) {
        accelDragSelect(pre, 30, 50);
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [firstText, 1, firstText, 2],
                [xBeforeSpan2.firstChild, 0, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, lastText, 0],
              ]
            : [
              [firstText, 1, firstText, 2],
              [xBeforeSpan2.firstChild, 0, lastText, 0],
            ],
          {id: "prev1: after accelDragSelect"}
        );
      } else {
        action(pre, 30);
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [firstText, 1, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, lastText, 0],
              ]
            : [[firstText, 1, lastText, 0]],
          {id: `prev1: after action(${action.name})`}
        );
      }
    } else if (test == "#prev2") {
      action(pre, 260);
      checkRanges(
        excludeNonSelectableNodes
          ? [
              [xBeforeSpan2.firstChild, 3, pre, 2],
              [xAfterSpan2, 0, pre, 4],
              [xAfterSpan3, 0, lastText, 0],
            ]
          : [[xBeforeSpan2.firstChild, 3, lastText, 0]],
        {id: `prev2: after action(${action.name})`}
      );
    } else if (test == "#prev3") {
      enableSelection('span2');
      action(pre, 400);
      checkRanges(
        excludeNonSelectableNodes
          ? [
              [span2.firstChild, 5, pre, 4],
              [xAfterSpan3, 0, lastText, 0],
            ]
          : [[span2.firstChild, 5, lastText, 0]],
        {id: `prev3: after action(${action.name}) with enabling selection of span2`}
      );
    } else if (test == "#prev4") {
      action(pre, 180, 65);
      checkRanges(
        excludeNonSelectableNodes
          ? [
              [xAfterSpan2.firstChild, 2, pre, 4],
              [xAfterSpan3, 0, lastText, 0],
            ]
          : [[xAfterSpan2.firstChild, 2, lastText, 0]],
        {id: `prev4: after action(${action.name})`}
      );
    } else if (test == "#prev5") {
      enableSelection('span3');
      action(pre, 440, 65);
      checkRanges(
        [[span3.firstChild, 10, lastText, 0]],
        {id: `prev5: after action(${action.name}) with enabling selection of span3`}
      );
    } else if (test == "#prev6") {
      action(pre, 140, 125);
      checkRanges(
        [[xAfterSpan3.firstChild, 2, lastText, 0]],
        {id: `prev6: after action(${action.name})`}
      );
    } else if (test == "#prev7") {
      if (action == accelDragSelect) {
        accelDragSelect(pre, 460, 500, 125);
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [xBeforeSpan2.firstChild, 0, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, lastText, 0],
                [lastText, 8, lastText, 10],
              ]
            : [
                [xBeforeSpan2.firstChild, 0, lastText, 0],
                [lastText, 8, lastText, 10],
              ],
          {id: "prev7: after accelDragSelect"}
        );
      } else {
        action(pre, 500, 125);
        checkRanges(
          [[lastText, 0, lastText, 10]],
          {id: `prev7: after action(${action.name})`}
        );
      }
    } else if (test == "#prev8") {
      if (action == accelDragSelect) {
        sel.removeAllRanges();
        synthesizeMouse(pre, 200, 125, {type: "mousedown", accelKey: true});
        synthesizeMouse(pre, 200, 120, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 100, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 80, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 210, 60, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 60, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 60, {type: "mouseup", accelKey: true});
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [xAfterSpan2.firstChild, 3, pre, 4],
                [xAfterSpan3, 0, xAfterSpan3.firstChild, 5],
              ]
            : [[xAfterSpan2.firstChild, 3, xAfterSpan3.firstChild, 5]],
          {id: "prev8: after dragging mouse with pressing accel key"}
        );
      }
    }
  } else {
    if (test == "#next1") {
      if (action == keyLeft) {
        keyLeft({shiftKey:true}, 2)
        checkRanges(
          excludeNonSelectableNodes
            ? [
              [firstText, 10, pre, 2],
              [xAfterSpan2, 0, pre, 4],
              [xAfterSpan3, 0, xAfterSpan3.firstChild, 8],
            ]
            : [[firstText, 10, xAfterSpan3.firstChild, 8]],
          {id: "next1: after Shift+ArrowLeft twice"}
        );
      } else if (action == keyRight) {
        keyRight({shiftKey:true}, 2)
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [firstText, 10, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, lastText, 2],
              ]
            : [[firstText, 10, lastText, 2]],
          {id: "next1: after Shift+ArrowRight twice"}
        );
      } else if (action == accelDragSelect) {
        accelDragSelect(pre, 30, 50);
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [firstText, 1, firstText, 2],
                [firstText, 10, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, xAfterSpan3.firstChild, 10],
              ]
            : [
                [firstText, 1, firstText, 2],
                [firstText, 10, xAfterSpan3.firstChild, 10],
              ],
          {id: "next1: after accelDragSelect"}
        );
      } else {
        action(pre, 30);
        checkRanges(
          [[firstText, 1, firstText, 10]],
          {id: `next1: after action(${action.name})`}
        );
      }
    } else if (test == "#next2") {
      action(pre, 260);
      checkRanges(
        [[firstText, 10, xBeforeSpan2.firstChild, 3]],
        {id: `next2: after action(${action.name})`}
      );
    } else if (test == "#next3") {
      enableSelection('span2');
      action(pre, 400);
      checkRanges(
        [[firstText, 10, span2.firstChild, 5]],
        {id: `next3: after action(${action.name}) with enabling selection in span2`}
      );
    } else if (test == "#next4") {
      action(pre, 180, 65);
      checkRanges(
        excludeNonSelectableNodes
          ? [
              [firstText, 10, pre, 2],
              [xAfterSpan2, 0, xAfterSpan2.firstChild, 2],
            ]
          : [[firstText, 10, xAfterSpan2.firstChild, 2]],
        {id: `next4: after action(${action.name})`}
      );
    } else if (test == "#next5") {
      enableSelection('span3');
      action(pre, 440, 65);
      checkRanges(
        excludeNonSelectableNodes
          ? [
              [firstText, 10, pre, 2],
              [xAfterSpan2, 0, span3.firstChild, 10],
            ]
          : [[firstText, 10, span3.firstChild, 10]],
        {id: `next5: after action(${action.name}) with enabling selection in span3`}
      );
    } else if (test == "#next6") {
      action(pre, 140, 125);
      checkRanges(
        excludeNonSelectableNodes
          ? [
              [firstText, 10, pre, 2],
              [xAfterSpan2, 0, pre, 4],
              [xAfterSpan3, 0, xAfterSpan3.firstChild, 2],
            ]
          : [[firstText, 10, xAfterSpan3.firstChild, 2]],
        {id: `next6: after action(${action.name})`}
      );
    } else if (test == "#next7") {
      if (action == keyRight) {
        keyRight({shiftKey:true}, 2)
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [firstText, 10, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, lastText, 2],
              ]
            : [[firstText, 10, lastText, 2]],
          {id: "next7: after Shift+ArrowRight twice"}
        );
      } else if (action == accelDragSelect) {
        accelDragSelect(pre, 460, 500, 125);
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [firstText, 10, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, xAfterSpan3.firstChild, 10],
                [lastText, 8, lastText, 10],
              ]
            : [
                [firstText, 10, xAfterSpan3.firstChild, 10],
                [lastText, 8, lastText, 10],
              ],
          {id: "next7: after accelDragSelect"}
        );
      } else {
        action(pre, 500, 125);
        checkRanges(
          excludeNonSelectableNodes
            ? [
                [firstText, 10, pre, 2],
                [xAfterSpan2, 0, pre, 4],
                [xAfterSpan3, 0, lastText, 10],
              ]
            : [[firstText, 10, lastText, 10]],
            {id: `next7: after action(${action.name}`}
        );
      }
    } else if (test == "#next8") {
      if (action == accelDragSelect) {
        sel.removeAllRanges();
        synthesizeMouse(pre, 200, 60, {type: "mousedown", accelKey: true});
        synthesizeMouse(pre, 180, 60, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 80, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 100, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 120, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 190, 125, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 125, {type: "mousemove", accelKey: true});
        synthesizeMouse(pre, 200, 125, {type: "mouseup", accelKey: true});
        checkRanges(
          excludeNonSelectableNodes
            ? [
              [xAfterSpan2.firstChild, 3, pre, 4],
              [xAfterSpan3, 0, xAfterSpan3.firstChild, 5],
            ]
            : [[xAfterSpan2.firstChild, 3,xAfterSpan3.firstChild, 5]],
          {id: "next8: after dragging with pressing Accel key"}
        );
      }
    }
  }
  document.documentElement.removeAttribute("class");
}

SimpleTest.waitForFocus(function(){setTimeout(runTest,0)});

</script>

</body>
</html>