2006-03-17 Anders Carlsson <andersca@mac.com>
[WebKit-https.git] / LayoutTests / editing / editing.js
1 //-------------------------------------------------------------------------------------------------------
2 // Java script library to run editing layout tests
3
4 var commandCount = 1;
5 var commandDelay = window.location.search.substring(1);
6 if (commandDelay == '')
7     commandDelay = 0;
8 var selection = window.getSelection();
9
10 //-------------------------------------------------------------------------------------------------------
11
12 function execTransposeCharactersCommand() {
13     document.execCommand("Transpose");
14 }
15 function transposeCharactersCommand() {
16     if (commandDelay > 0) {
17         window.setTimeout(execTransposeCharactersCommand, commandCount * commandDelay);
18         commandCount++;
19     }
20     else {
21         execTransposeCharactersCommand();
22     }
23 }
24
25 //-------------------------------------------------------------------------------------------------------
26
27 function execMoveSelectionForwardByCharacterCommand() {
28     selection.modify("move", "forward", "character");
29 }
30 function moveSelectionForwardByCharacterCommand() {
31     if (commandDelay > 0) {
32         window.setTimeout(execMoveSelectionForwardByCharacterCommand, commandCount * commandDelay);
33         commandCount++;
34     }
35     else {
36         execMoveSelectionForwardByCharacterCommand();
37     }
38 }
39
40 //-------------------------------------------------------------------------------------------------------
41
42 function execExtendSelectionForwardByCharacterCommand() {
43     selection.modify("extend", "forward", "character");
44 }
45 function extendSelectionForwardByCharacterCommand() {
46     if (commandDelay > 0) {
47         window.setTimeout(execExtendSelectionForwardByCharacterCommand, commandCount * commandDelay);
48         commandCount++;
49     }
50     else {
51         execExtendSelectionForwardByCharacterCommand();
52     }
53 }
54
55 //-------------------------------------------------------------------------------------------------------
56
57 function execMoveSelectionForwardByWordCommand() {
58     selection.modify("move", "forward", "word");
59 }
60 function moveSelectionForwardByWordCommand() {
61     if (commandDelay > 0) {
62         window.setTimeout(execMoveSelectionForwardByWordCommand, commandCount * commandDelay);
63         commandCount++;
64     }
65     else {
66         execMoveSelectionForwardByWordCommand();
67     }
68 }
69
70 //-------------------------------------------------------------------------------------------------------
71
72 function execExtendSelectionForwardByWordCommand() {
73     selection.modify("extend", "forward", "word");
74 }
75 function extendSelectionForwardByWordCommand() {
76     if (commandDelay > 0) {
77         window.setTimeout(execExtendSelectionForwardByWordCommand, commandCount * commandDelay);
78         commandCount++;
79     }
80     else {
81         execExtendSelectionForwardByWordCommand();
82     }
83 }
84
85 //-------------------------------------------------------------------------------------------------------
86
87 function execMoveSelectionForwardByLineCommand() {
88     selection.modify("move", "forward", "line");
89 }
90 function moveSelectionForwardByLineCommand() {
91     if (commandDelay > 0) {
92         window.setTimeout(execMoveSelectionForwardByLineCommand, commandCount * commandDelay);
93         commandCount++;
94     }
95     else {
96         execMoveSelectionForwardByLineCommand();
97     }
98 }
99
100 //-------------------------------------------------------------------------------------------------------
101
102 function execExtendSelectionForwardByLineCommand() {
103     selection.modify("extend", "forward", "line");
104 }
105 function extendSelectionForwardByLineCommand() {
106     if (commandDelay > 0) {
107         window.setTimeout(execExtendSelectionForwardByLineCommand, commandCount * commandDelay);
108         commandCount++;
109     }
110     else {
111         execExtendSelectionForwardByLineCommand();
112     }
113 }
114
115 //-------------------------------------------------------------------------------------------------------
116
117 function execMoveSelectionBackwardByCharacterCommand() {
118     selection.modify("move", "backward", "character");
119 }
120 function moveSelectionBackwardByCharacterCommand() {
121     if (commandDelay > 0) {
122         window.setTimeout(execMoveSelectionBackwardByCharacterCommand, commandCount * commandDelay);
123         commandCount++;
124     }
125     else {
126         execMoveSelectionBackwardByCharacterCommand();
127     }
128 }
129
130 //-------------------------------------------------------------------------------------------------------
131
132 function execExtendSelectionBackwardByCharacterCommand() {
133     selection.modify("extend", "backward", "character");
134 }
135 function extendSelectionBackwardByCharacterCommand() {
136     if (commandDelay > 0) {
137         window.setTimeout(execExtendSelectionBackwardByCharacterCommand, commandCount * commandDelay);
138         commandCount++;
139     }
140     else {
141         execExtendSelectionBackwardByCharacterCommand();
142     }
143 }
144
145 //-------------------------------------------------------------------------------------------------------
146
147 function execMoveSelectionBackwardByWordCommand() {
148     selection.modify("move", "backward", "word");
149 }
150 function moveSelectionBackwardByWordCommand() {
151     if (commandDelay > 0) {
152         window.setTimeout(execMoveSelectionBackwardByWordCommand, commandCount * commandDelay);
153         commandCount++;
154     }
155     else {
156         execMoveSelectionBackwardByWordCommand();
157     }
158 }
159
160 //-------------------------------------------------------------------------------------------------------
161
162 function execExtendSelectionBackwardByWordCommand() {
163     selection.modify("extend", "backward", "word");
164 }
165 function extendSelectionBackwardByWordCommand() {
166     if (commandDelay > 0) {
167         window.setTimeout(execExtendSelectionBackwardByWordCommand, commandCount * commandDelay);
168         commandCount++;
169     }
170     else {
171         execExtendSelectionBackwardByWordCommand();
172     }
173 }
174
175 //-------------------------------------------------------------------------------------------------------
176
177 function execMoveSelectionBackwardByLineCommand() {
178     selection.modify("move", "backward", "line");
179 }
180 function moveSelectionBackwardByLineCommand() {
181     if (commandDelay > 0) {
182         window.setTimeout(execMoveSelectionBackwardByLineCommand, commandCount * commandDelay);
183         commandCount++;
184     }
185     else {
186         execMoveSelectionBackwardByLineCommand();
187     }
188 }
189
190 //-------------------------------------------------------------------------------------------------------
191
192 function execExtendSelectionBackwardByLineCommand() {
193     selection.modify("extend", "backward", "line");
194 }
195 function extendSelectionBackwardByLineCommand() {
196     if (commandDelay > 0) {
197         window.setTimeout(execExtendSelectionBackwardByLineCommand, commandCount * commandDelay);
198         commandCount++;
199     }
200     else {
201         execExtendSelectionBackwardByLineCommand();
202     }
203 }
204
205 //-------------------------------------------------------------------------------------------------------
206
207 function execBoldCommand() {
208     document.execCommand("Bold");
209 }
210 function boldCommand() {
211     if (commandDelay > 0) {
212         window.setTimeout(execBoldCommand, commandCount * commandDelay);
213         commandCount++;
214     }
215     else {
216         execBoldCommand();
217     }
218 }
219
220 //-------------------------------------------------------------------------------------------------------
221
222 function execUnderlineCommand() {
223     document.execCommand("Underline");
224 }
225 function underlineCommand() {
226     if (commandDelay > 0) {
227         window.setTimeout(execUnderlineCommand, commandCount * commandDelay);
228         commandCount++;
229     }
230     else {
231         execUnderlineCommand();
232     }
233 }
234
235 //-------------------------------------------------------------------------------------------------------
236
237 function execFontNameCommand() {
238     document.execCommand("FontName", false, "Courier");
239 }
240 function fontNameCommand() {
241     if (commandDelay > 0) {
242         window.setTimeout(execFontNameCommand, commandCount * commandDelay);
243         commandCount++;
244     }
245     else {
246         execFontNameCommand();
247     }
248 }
249
250 //-------------------------------------------------------------------------------------------------------
251
252 function execFontSizeCommand(s) {
253     if (arguments.length == 0 || s == undefined || s.length == 0)
254         s = '12px';
255     document.execCommand("FontSize", false, s);
256 }
257 function fontSizeCommand(s) {
258     if (commandDelay > 0) {
259         window.setTimeout(execFontSizeCommand, commandCount * commandDelay, s);
260         commandCount++;
261     }
262     else {
263         execFontSizeCommand(s);
264     }
265 }
266
267 //-------------------------------------------------------------------------------------------------------
268
269 function execFontSizeDeltaCommand(s) {
270     if (arguments.length == 0 || s == undefined || s.length == 0)
271         s = '1px';
272     document.execCommand("FontSizeDelta", false, s);
273 }
274 function fontSizeDeltaCommand(s) {
275     if (commandDelay > 0) {
276         window.setTimeout(execFontSizeDeltaCommand, commandCount * commandDelay, s);
277         commandCount++;
278     }
279     else {
280         execFontSizeDeltaCommand(s);
281     }
282 }
283
284 //-------------------------------------------------------------------------------------------------------
285
286 function execItalicCommand() {
287     document.execCommand("Italic");
288 }
289 function italicCommand() {
290     if (commandDelay > 0) {
291         window.setTimeout(execItalicCommand, commandCount * commandDelay);
292         commandCount++;
293     }
294     else {
295         execItalicCommand();
296     }
297 }
298
299
300 //-------------------------------------------------------------------------------------------------------
301
302 function execJustifyCenterCommand() {
303     document.execCommand("JustifyCenter");
304 }
305 function justifyCenterCommand() {
306     if (commandDelay > 0) {
307         window.setTimeout(execJustifyCenterCommand, commandCount * commandDelay);
308         commandCount++;
309     }
310     else {
311         execJustifyCenterCommand();
312     }
313 }
314
315
316 //-------------------------------------------------------------------------------------------------------
317
318 function execJustifyLeftCommand() {
319     document.execCommand("JustifyLeft");
320 }
321 function justifyLeftCommand() {
322     if (commandDelay > 0) {
323         window.setTimeout(execJustifyLeftCommand, commandCount * commandDelay);
324         commandCount++;
325     }
326     else {
327         execJustifyLeftCommand();
328     }
329 }
330
331
332 //-------------------------------------------------------------------------------------------------------
333
334 function execJustifyRightCommand() {
335     document.execCommand("JustifyRight");
336 }
337 function justifyRightCommand() {
338     if (commandDelay > 0) {
339         window.setTimeout(execJustifyRightCommand, commandCount * commandDelay);
340         commandCount++;
341     }
342     else {
343         execJustifyRightCommand();
344     }
345 }
346
347 //-------------------------------------------------------------------------------------------------------
348
349 function execInsertHTMLCommand(html) {
350     document.execCommand("InsertHTML", false, html);
351 }
352 function insertHTMLCommand(html) {
353     if (commandDelay > 0) {
354         window.setTimeout(execInsertHTMLCommand, commandCount * commandDelay, html);
355         commandCount++;
356     }
357     else {
358         execInsertHTMLCommand(html);
359     }
360 }
361
362 //-------------------------------------------------------------------------------------------------------
363
364 function execInsertImageCommand(imgSrc) {
365     document.execCommand("InsertImage", false, imgSrc);
366 }
367 function insertImageCommand(imgSrc) {
368     if (commandDelay > 0) {
369         window.setTimeout(execInsertImageCommand, commandCount * commandDelay, imgSrc);
370         commandCount++;
371     }
372     else {
373         execInsertImageCommand(imgSrc);
374     }
375 }
376
377 //-------------------------------------------------------------------------------------------------------
378
379 function execInsertLineBreakCommand() {
380     document.execCommand("InsertLineBreak");
381 }
382 function insertLineBreakCommand() {
383     if (commandDelay > 0) {
384         window.setTimeout(execInsertLineBreakCommand, commandCount * commandDelay);
385         commandCount++;
386     }
387     else {
388         execInsertLineBreakCommand();
389     }
390 }
391
392 //-------------------------------------------------------------------------------------------------------
393  
394 function execInsertParagraphCommand() {
395     document.execCommand("InsertParagraph");
396 }
397 function insertParagraphCommand() {
398     if (commandDelay > 0) {
399         window.setTimeout(execInsertParagraphCommand, commandCount * commandDelay);
400         commandCount++;
401     }
402     else {
403         execInsertParagraphCommand();
404     }
405 }
406
407 //-------------------------------------------------------------------------------------------------------
408
409 function execInsertNewlineInQuotedContentCommand() {
410     document.execCommand("InsertNewlineInQuotedContent");
411 }
412 function insertNewlineInQuotedContentCommand() {
413     if (commandDelay > 0) {
414         window.setTimeout(execInsertNewlineInQuotedContentCommand, commandCount * commandDelay);
415         commandCount++;
416     }
417     else {
418         execInsertNewlineInQuotedContentCommand();
419     }
420 }
421
422 //-------------------------------------------------------------------------------------------------------
423
424 function execTypeCharacterCommand(c) {
425     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
426         c = 'x';
427     document.execCommand("InsertText", false, c);
428 }
429 function typeCharacterCommand(c) {
430     if (commandDelay > 0) {
431         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay, c);
432         commandCount++;
433     }
434     else {
435         execTypeCharacterCommand(c);
436     }
437 }
438
439 //-------------------------------------------------------------------------------------------------------
440
441 function execSelectAllCommand() {
442     document.execCommand("SelectAll");
443 }
444 function selectAllCommand() {
445     if (commandDelay > 0) {
446         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
447         commandCount++;
448     }
449     else {
450         execSelectAllCommand();
451     }
452 }
453
454 //-------------------------------------------------------------------------------------------------------
455
456 function execStrikethroughCommand() {
457     document.execCommand("Strikethrough");
458 }
459 function strikethroughCommand() {
460     if (commandDelay > 0) {
461         window.setTimeout(execStrikethroughCommand, commandCount * commandDelay);
462         commandCount++;
463     }
464     else {
465         execStrikethroughCommand();
466     }
467 }
468
469 //-------------------------------------------------------------------------------------------------------
470
471 function execUndoCommand() {
472     document.execCommand("Undo");
473 }
474 function undoCommand() {
475     if (commandDelay > 0) {
476         window.setTimeout(execUndoCommand, commandCount * commandDelay);
477         commandCount++;
478     }
479     else {
480         execUndoCommand();
481     }
482 }
483
484 //-------------------------------------------------------------------------------------------------------
485
486 function execRedoCommand() {
487     document.execCommand("Redo");
488 }
489 function redoCommand() {
490     if (commandDelay > 0) {
491         window.setTimeout(execRedoCommand, commandCount * commandDelay);
492         commandCount++;
493     }
494     else {
495         execRedoCommand();
496     }
497 }
498
499 //-------------------------------------------------------------------------------------------------------
500
501 function execChangeRootSize() {
502     document.getElementById("root").style.width = "600px";
503 }
504 function changeRootSize() {
505     if (commandDelay > 0) {
506         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
507         commandCount++;
508     }
509     else {
510         execChangeRootSize();
511     }
512 }
513
514 //-------------------------------------------------------------------------------------------------------
515
516 function execCutCommand() {
517     document.execCommand("Cut");
518 }
519 function cutCommand() {
520     if (commandDelay > 0) {
521         window.setTimeout(execCutCommand, commandCount * commandDelay);
522         commandCount++;
523     }
524     else {
525         execCutCommand();
526     }
527 }
528
529 //-------------------------------------------------------------------------------------------------------
530
531 function execCopyCommand() {
532     document.execCommand("Copy");
533 }
534 function copyCommand() {
535     if (commandDelay > 0) {
536         window.setTimeout(execCopyCommand, commandCount * commandDelay);
537         commandCount++;
538     }
539     else {
540         execCopyCommand();
541     }
542 }
543
544 //-------------------------------------------------------------------------------------------------------
545
546 function execPasteCommand() {
547     document.execCommand("Paste");
548 }
549 function pasteCommand() {
550     if (commandDelay > 0) {
551         window.setTimeout(execPasteCommand, commandCount * commandDelay);
552         commandCount++;
553     }
554     else {
555         execPasteCommand();
556     }
557 }
558
559 //-------------------------------------------------------------------------------------------------------
560
561 function execCreateLinkCommand(url) {
562     document.execCommand("CreateLink", false, url);
563 }
564 function createLinkCommand(url) {
565     if (commandDelay > 0) {
566         window.setTimeout(execCreateLinkCommand, commandCount * commandDelay, url);
567         commandCount++;
568     }
569     else {
570         execCreateLinkCommand(url);
571     }
572 }
573
574 //-------------------------------------------------------------------------------------------------------
575
576 function execPasteAndMatchStyleCommand() {
577     document.execCommand("PasteAndMatchStyle");
578 }
579 function pasteAndMatchStyleCommand() {
580     if (commandDelay > 0) {
581         window.setTimeout(execPasteAndMatchStyleCommand, commandCount * commandDelay);
582         commandCount++;
583     }
584     else {
585         execPasteAndMatchStyleCommand();
586     }
587 }
588
589 //-------------------------------------------------------------------------------------------------------
590
591 function execDeleteCommand() {
592     document.execCommand("Delete");
593 }
594 function deleteCommand() {
595     if (commandDelay > 0) {
596         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
597         commandCount++;
598     }
599     else {
600         execDeleteCommand();
601     }
602 }
603
604 //-------------------------------------------------------------------------------------------------------
605
606 function execForwardDeleteCommand() {
607     document.execCommand("ForwardDelete");
608 }
609 function forwardDeleteCommand() {
610     if (commandDelay > 0) {
611         window.setTimeout(execForwardDeleteCommand, commandCount * commandDelay);
612         commandCount++;
613     }
614     else {
615         execForwardDeleteCommand();
616     }
617 }
618
619 //-------------------------------------------------------------------------------------------------------
620
621 function runEditingTest() {
622     var elem = document.getElementById("test");
623     var selection = window.getSelection();
624     selection.setPosition(elem, 0);
625     editingTest();
626 }
627
628 //-------------------------------------------------------------------------------------------------------
629
630
631 function execBackColorCommand() {
632     document.execCommand("BackColor", false, "Chartreuse");
633 }
634 function backColorCommand() {
635     if (commandDelay > 0) {
636         window.setTimeout(execBackColorCommand, commandCount * commandDelay);
637         commandCount++;
638     }
639     else {
640         execBackColorCommand();
641     }
642 }
643
644 //-------------------------------------------------------------------------------------------------------
645
646
647 function runCommand(command, arg1, arg2) {
648     document.execCommand(command,arg1,arg2);
649 }
650
651 function executeCommand(command,arg1,arg2) {
652     if (commandDelay > 0) {
653         window.setTimeout(runCommand, commandCount * commandDelay);
654         commandCount++;
655     }
656     else {
657         runCommand(command,arg1,arg2);
658     }
659 }
660