Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / editing / editing.js
blobfb9a5ecc4945262521801d1f8c71f1d8c8bd0e71
1 //-------------------------------------------------------------------------------------------------------
2 // Java script library to run editing layout tests
4 var commandCount = 1;
5 var commandDelay = window.location.search.substring(1);
6 if (commandDelay == '')
7     commandDelay = 0;
8 var selection = window.getSelection();
10 //-------------------------------------------------------------------------------------------------------
12 function execSetSelectionCommand(sn, so, en, eo) {
13     window.getSelection().setBaseAndExtent(sn, so, en, eo);
16 // Args are startNode, startOffset, endNode, endOffset
17 function setSelectionCommand(sn, so, en, eo) {
18     if (commandDelay > 0) {
19         queueCommand(execSetSelectionCommand.bind(execSetSelectionCommand, sn, so, en, eo), commandCount * commandDelay);
20         commandCount++;
21     } else
22         execSetSelectionCommand(sn, so, en, eo);
25 //-------------------------------------------------------------------------------------------------------
27 function execTransposeCharactersCommand() {
28     document.execCommand("Transpose");
30 function transposeCharactersCommand() {
31     if (commandDelay > 0) {
32         queueCommand(execTransposeCharactersCommand, commandCount * commandDelay);
33         commandCount++;
34     }
35     else {
36         execTransposeCharactersCommand();
37     }
40 //-------------------------------------------------------------------------------------------------------
42 function execMoveSelectionLeftByCharacterCommand() {
43     selection.modify("move", "left", "character");
45 function moveSelectionLeftByCharacterCommand() {
46     if (commandDelay > 0) {
47         queueCommand(execMoveSelectionLeftByCharacterCommand, commandCount * commandDelay);
48         commandCount++;
49     }
50     else {
51         execMoveSelectionLeftByCharacterCommand();
52     }
55 //-------------------------------------------------------------------------------------------------------
57 function execMoveSelectionRightByCharacterCommand() {
58     selection.modify("move", "Right", "character");
60 function moveSelectionRightByCharacterCommand() {
61     if (commandDelay > 0) {
62         queueCommand(execMoveSelectionRightByCharacterCommand, commandCount * commandDelay);
63         commandCount++;
64     }
65     else {
66         execMoveSelectionRightByCharacterCommand();
67     }
70 //-------------------------------------------------------------------------------------------------------
72 function execExtendSelectionLeftByCharacterCommand() {
73     selection.modify("extend", "left", "character");
75 function extendSelectionLeftByCharacterCommand() {
76     if (commandDelay > 0) {
77         queueCommand(execExtendSelectionLeftByCharacterCommand, commandCount * commandDelay);
78         commandCount++;
79     }
80     else {
81         execExtendSelectionLeftByCharacterCommand();
82     }
85 //-------------------------------------------------------------------------------------------------------
87 function execExtendSelectionRightByCharacterCommand() {
88     selection.modify("extend", "Right", "character");
90 function extendSelectionRightByCharacterCommand() {
91     if (commandDelay > 0) {
92         queueCommand(execExtendSelectionRightByCharacterCommand, commandCount * commandDelay);
93         commandCount++;
94     }
95     else {
96         execExtendSelectionRightByCharacterCommand();
97     }
100 //-------------------------------------------------------------------------------------------------------
102 function execMoveSelectionForwardByCharacterCommand() {
103     selection.modify("move", "forward", "character");
105 function moveSelectionForwardByCharacterCommand() {
106     if (commandDelay > 0) {
107         queueCommand(execMoveSelectionForwardByCharacterCommand, commandCount * commandDelay);
108         commandCount++;
109     }
110     else {
111         execMoveSelectionForwardByCharacterCommand();
112     }
115 //-------------------------------------------------------------------------------------------------------
117 function execExtendSelectionForwardByCharacterCommand() {
118     selection.modify("extend", "forward", "character");
120 function extendSelectionForwardByCharacterCommand() {
121     if (commandDelay > 0) {
122         queueCommand(execExtendSelectionForwardByCharacterCommand, commandCount * commandDelay);
123         commandCount++;
124     }
125     else {
126         execExtendSelectionForwardByCharacterCommand();
127     }
130 //-------------------------------------------------------------------------------------------------------
132 function execMoveSelectionForwardByWordCommand() {
133     selection.modify("move", "forward", "word");
135 function moveSelectionForwardByWordCommand() {
136     if (commandDelay > 0) {
137         queueCommand(execMoveSelectionForwardByWordCommand, commandCount * commandDelay);
138         commandCount++;
139     }
140     else {
141         execMoveSelectionForwardByWordCommand();
142     }
145 //-------------------------------------------------------------------------------------------------------
147 function execExtendSelectionForwardByWordCommand() {
148     selection.modify("extend", "forward", "word");
150 function extendSelectionForwardByWordCommand() {
151     if (commandDelay > 0) {
152         queueCommand(execExtendSelectionForwardByWordCommand, commandCount * commandDelay);
153         commandCount++;
154     }
155     else {
156         execExtendSelectionForwardByWordCommand();
157     }
160 //-------------------------------------------------------------------------------------------------------
162 function execMoveSelectionForwardBySentenceCommand() {
163     selection.modify("move", "forward", "sentence");
165 function moveSelectionForwardBySentenceCommand() {
166     if (commandDelay > 0) {
167         queueCommand(execMoveSelectionForwardBySentenceCommand, commandCount * commandDelay);
168         commandCount++;
169     }
170     else {
171         execMoveSelectionForwardBySentenceCommand();
172     }
175 //-------------------------------------------------------------------------------------------------------
177 function execExtendSelectionForwardBySentenceCommand() {
178     selection.modify("extend", "forward", "sentence");
180 function extendSelectionForwardBySentenceCommand() {
181     if (commandDelay > 0) {
182         queueCommand(execExtendSelectionForwardBySentenceCommand, commandCount * commandDelay);
183         commandCount++;
184     }
185     else {
186         execExtendSelectionForwardBySentenceCommand();
187     }
190 //-------------------------------------------------------------------------------------------------------
192 function execMoveSelectionForwardByLineCommand() {
193     selection.modify("move", "forward", "line");
195 function moveSelectionForwardByLineCommand() {
196     if (commandDelay > 0) {
197         queueCommand(execMoveSelectionForwardByLineCommand, commandCount * commandDelay);
198         commandCount++;
199     }
200     else {
201         execMoveSelectionForwardByLineCommand();
202     }
205 //-------------------------------------------------------------------------------------------------------
207 function execExtendSelectionForwardByLineCommand() {
208     selection.modify("extend", "forward", "line");
210 function extendSelectionForwardByLineCommand() {
211     if (commandDelay > 0) {
212         queueCommand(execExtendSelectionForwardByLineCommand, commandCount * commandDelay);
213         commandCount++;
214     }
215     else {
216         execExtendSelectionForwardByLineCommand();
217     }
220 //-------------------------------------------------------------------------------------------------------
222 function execMoveSelectionForwardByLineBoundaryCommand() {
223     selection.modify("move", "forward", "lineBoundary");
225 function moveSelectionForwardByLineBoundaryCommand() {
226     if (commandDelay > 0) {
227         queueCommand(execMoveSelectionForwardByLineBoundaryCommand, commandCount * commandDelay);
228         commandCount++;
229     }
230     else {
231         execMoveSelectionForwardByLineBoundaryCommand();
232     }
235 //-------------------------------------------------------------------------------------------------------
237 function execExtendSelectionForwardByLineBoundaryCommand() {
238     selection.modify("extend", "forward", "lineBoundary");
240 function extendSelectionForwardByLineBoundaryCommand() {
241     if (commandDelay > 0) {
242         queueCommand(execExtendSelectionForwardByLineBoundaryCommand, commandCount * commandDelay);
243         commandCount++;
244     }
245     else {
246         execExtendSelectionForwardByLineBoundaryCommand();
247     }
250 //-------------------------------------------------------------------------------------------------------
252 function execMoveSelectionBackwardByCharacterCommand() {
253     selection.modify("move", "backward", "character");
255 function moveSelectionBackwardByCharacterCommand() {
256     if (commandDelay > 0) {
257         queueCommand(execMoveSelectionBackwardByCharacterCommand, commandCount * commandDelay);
258         commandCount++;
259     }
260     else {
261         execMoveSelectionBackwardByCharacterCommand();
262     }
265 //-------------------------------------------------------------------------------------------------------
267 function execExtendSelectionBackwardByCharacterCommand() {
268     selection.modify("extend", "backward", "character");
270 function extendSelectionBackwardByCharacterCommand() {
271     if (commandDelay > 0) {
272         queueCommand(execExtendSelectionBackwardByCharacterCommand, commandCount * commandDelay);
273         commandCount++;
274     }
275     else {
276         execExtendSelectionBackwardByCharacterCommand();
277     }
280 //-------------------------------------------------------------------------------------------------------
282 function execMoveSelectionBackwardByWordCommand() {
283     selection.modify("move", "backward", "word");
285 function moveSelectionBackwardByWordCommand() {
286     if (commandDelay > 0) {
287         queueCommand(execMoveSelectionBackwardByWordCommand, commandCount * commandDelay);
288         commandCount++;
289     }
290     else {
291         execMoveSelectionBackwardByWordCommand();
292     }
295 //-------------------------------------------------------------------------------------------------------
297 function execExtendSelectionBackwardByWordCommand() {
298     selection.modify("extend", "backward", "word");
300 function extendSelectionBackwardByWordCommand() {
301     if (commandDelay > 0) {
302         queueCommand(execExtendSelectionBackwardByWordCommand, commandCount * commandDelay);
303         commandCount++;
304     }
305     else {
306         execExtendSelectionBackwardByWordCommand();
307     }
310 //-------------------------------------------------------------------------------------------------------
312 function execMoveSelectionBackwardBySentenceCommand() {
313     selection.modify("move", "backward", "sentence");
315 function moveSelectionBackwardBySentenceCommand() {
316     if (commandDelay > 0) {
317         queueCommand(execMoveSelectionBackwardBySentenceCommand, commandCount * commandDelay);
318         commandCount++;
319     }
320     else {
321         execMoveSelectionBackwardBySentenceCommand();
322     }
325 //-------------------------------------------------------------------------------------------------------
327 function execExtendSelectionBackwardBySentenceCommand() {
328     selection.modify("extend", "backward", "sentence");
330 function extendSelectionBackwardBySentenceCommand() {
331     if (commandDelay > 0) {
332         queueCommand(execExtendSelectionBackwardBySentenceCommand, commandCount * commandDelay);
333         commandCount++;
334     }
335     else {
336         execExtendSelectionBackwardBySentenceCommand();
337     }
340 //-------------------------------------------------------------------------------------------------------
342 function execMoveSelectionBackwardByLineCommand() {
343     selection.modify("move", "backward", "line");
345 function moveSelectionBackwardByLineCommand() {
346     if (commandDelay > 0) {
347         queueCommand(execMoveSelectionBackwardByLineCommand, commandCount * commandDelay);
348         commandCount++;
349     }
350     else {
351         execMoveSelectionBackwardByLineCommand();
352     }
355 //-------------------------------------------------------------------------------------------------------
357 function execExtendSelectionBackwardByLineCommand() {
358     selection.modify("extend", "backward", "line");
360 function extendSelectionBackwardByLineCommand() {
361     if (commandDelay > 0) {
362         queueCommand(execExtendSelectionBackwardByLineCommand, commandCount * commandDelay);
363         commandCount++;
364     }
365     else {
366         execExtendSelectionBackwardByLineCommand();
367     }
370 //-------------------------------------------------------------------------------------------------------
372 function execExtendSelectionBackwardByLineBoundaryCommand() {
373     selection.modify("extend", "backward", "lineBoundary");
375 function extendSelectionBackwardByLineBoundaryCommand() {
376     if (commandDelay > 0) {
377         queueCommand(execExtendSelectionBackwardByLineBoundaryCommand, commandCount * commandDelay);
378         commandCount++;
379     }
380     else {
381         execExtendSelectionBackwardByLineBoundaryCommand();
382     }
385 //-------------------------------------------------------------------------------------------------------
387 function execMoveSelectionBackwardByLineBoundaryCommand() {
388     selection.modify("move", "backward", "lineBoundary");
390 function moveSelectionBackwardByLineBoundaryCommand() {
391     if (commandDelay > 0) {
392         queueCommand(execMoveSelectionBackwardByLineBoundaryCommand, commandCount * commandDelay);
393         commandCount++;
394     }
395     else {
396         execMoveSelectionBackwardByLineBoundaryCommand();
397     }
400 //-------------------------------------------------------------------------------------------------------
402 function doubleClick(x, y) {
403     eventSender.mouseMoveTo(x, y);
404     eventSender.mouseDown();
405     eventSender.mouseUp();
406     eventSender.mouseDown();
407     eventSender.mouseUp();
410 function doubleClickAtSelectionStart() {
411     var rects = window.getSelection().getRangeAt(0).getClientRects();
412     var x = rects[0].left;
413     var y = rects[0].top;
414     doubleClick(x, y);
417 //-------------------------------------------------------------------------------------------------------
419 function execBoldCommand() {
420     document.execCommand("Bold");
421     debugForDumpAsText("execBoldCommand");
423 function boldCommand() {
424     if (commandDelay > 0) {
425         queueCommand(execBoldCommand, commandCount * commandDelay);
426         commandCount++;
427     }
428     else {
429         execBoldCommand();
430     }
433 //-------------------------------------------------------------------------------------------------------
435 function execUnderlineCommand() {
436     document.execCommand("Underline");
437     debugForDumpAsText("execUnderlineCommand");
439 function underlineCommand() {
440     if (commandDelay > 0) {
441         queueCommand(execUnderlineCommand, commandCount * commandDelay);
442         commandCount++;
443     }
444     else {
445         execUnderlineCommand();
446     }
449 //-------------------------------------------------------------------------------------------------------
451 function execFontNameCommand() {
452     document.execCommand("FontName", false, "Courier");
453     debugForDumpAsText("execFontNameCommand");
455 function fontNameCommand() {
456     if (commandDelay > 0) {
457         queueCommand(execFontNameCommand, commandCount * commandDelay);
458         commandCount++;
459     }
460     else {
461         execFontNameCommand();
462     }
465 //-------------------------------------------------------------------------------------------------------
467 function execFontSizeCommand(s) {
468     if (arguments.length == 0 || s == undefined || s.length == 0)
469         s = '12px';
470     document.execCommand("FontSize", false, s);
471     debugForDumpAsText("execFontSizeCommand");
473 function fontSizeCommand(s) {
474     if (commandDelay > 0) {
475         queueCommand(execFontSizeCommand, commandCount * commandDelay, s);
476         commandCount++;
477     }
478     else {
479         execFontSizeCommand(s);
480     }
483 //-------------------------------------------------------------------------------------------------------
485 function execFontSizeDeltaCommand(s) {
486     if (arguments.length == 0 || s == undefined || s.length == 0)
487         s = '1px';
488     document.execCommand("FontSizeDelta", false, s);
489     debugForDumpAsText("execFontSizeDeltaCommand");
491 function fontSizeDeltaCommand(s) {
492     if (commandDelay > 0) {
493         queueCommand(execFontSizeDeltaCommand.bind(execFontSizeDeltaCommand, s), commandCount * commandDelay);
494         commandCount++;
495     }
496     else {
497         execFontSizeDeltaCommand(s);
498     }
501 //-------------------------------------------------------------------------------------------------------
503 function execItalicCommand() {
504     document.execCommand("Italic");
505     debugForDumpAsText("execItalicCommand");
507 function italicCommand() {
508     if (commandDelay > 0) {
509         queueCommand(execItalicCommand, commandCount * commandDelay);
510         commandCount++;
511     }
512     else {
513         execItalicCommand();
514     }
518 //-------------------------------------------------------------------------------------------------------
520 function execJustifyCenterCommand() {
521     document.execCommand("JustifyCenter");
522     debugForDumpAsText("execJustifyCenterCommand");
524 function justifyCenterCommand() {
525     if (commandDelay > 0) {
526         queueCommand(execJustifyCenterCommand, commandCount * commandDelay);
527         commandCount++;
528     }
529     else {
530         execJustifyCenterCommand();
531     }
535 //-------------------------------------------------------------------------------------------------------
537 function execJustifyLeftCommand() {
538     document.execCommand("JustifyLeft");
539     debugForDumpAsText("execJustifyLeftCommand");
541 function justifyLeftCommand() {
542     if (commandDelay > 0) {
543         queueCommand(execJustifyLeftCommand, commandCount * commandDelay);
544         commandCount++;
545     }
546     else {
547         execJustifyLeftCommand();
548     }
552 //-------------------------------------------------------------------------------------------------------
554 function execJustifyRightCommand() {
555     document.execCommand("JustifyRight");
556     debugForDumpAsText("execJustifyRightCommand");
558 function justifyRightCommand() {
559     if (commandDelay > 0) {
560         queueCommand(execJustifyRightCommand, commandCount * commandDelay);
561         commandCount++;
562     }
563     else {
564         execJustifyRightCommand();
565     }
568 //-------------------------------------------------------------------------------------------------------
570 function execInsertHTMLCommand(html) {
571     document.execCommand("InsertHTML", false, html);
572     debugForDumpAsText("execInsertHTMLCommand");
574 function insertHTMLCommand(html) {
575     if (commandDelay > 0) {
576         queueCommand(execInsertHTMLCommand.bind(execInsertHTMLCommand, html), commandCount * commandDelay);
577         commandCount++;
578     }
579     else {
580         execInsertHTMLCommand(html);
581     }
584 //-------------------------------------------------------------------------------------------------------
586 function execInsertImageCommand(imgSrc) {
587     document.execCommand("InsertImage", false, imgSrc);
588     debugForDumpAsText("execInsertImageCommand");
590 function insertImageCommand(imgSrc) {
591     if (commandDelay > 0) {
592         queueCommand(execInsertImageCommand.bind(execInsertImageCommand, imgSrc), commandCount * commandDelay);
593         commandCount++;
594     }
595     else {
596         execInsertImageCommand(imgSrc);
597     }
600 //-------------------------------------------------------------------------------------------------------
602 function execInsertLineBreakCommand() {
603     document.execCommand("InsertLineBreak");
604     debugForDumpAsText("execInsertLineBreakCommand");
606 function insertLineBreakCommand() {
607     if (commandDelay > 0) {
608         queueCommand(execInsertLineBreakCommand, commandCount * commandDelay);
609         commandCount++;
610     }
611     else {
612         execInsertLineBreakCommand();
613     }
616 //-------------------------------------------------------------------------------------------------------
618 function execInsertParagraphCommand() {
619     document.execCommand("InsertParagraph");
620     debugForDumpAsText("execInsertParagraphCommand");
622 function insertParagraphCommand() {
623     if (commandDelay > 0) {
624         queueCommand(execInsertParagraphCommand, commandCount * commandDelay);
625         commandCount++;
626     }
627     else {
628         execInsertParagraphCommand();
629     }
632 //-------------------------------------------------------------------------------------------------------
634 function execInsertNewlineInQuotedContentCommand() {
635     document.execCommand("InsertNewlineInQuotedContent");
636     debugForDumpAsText("execInsertNewlineInQuotedContentCommand");
638 function insertNewlineInQuotedContentCommand() {
639     if (commandDelay > 0) {
640         queueCommand(execInsertNewlineInQuotedContentCommand, commandCount * commandDelay);
641         commandCount++;
642     }
643     else {
644         execInsertNewlineInQuotedContentCommand();
645     }
648 //-------------------------------------------------------------------------------------------------------
650 function execTypeCharacterCommand(c) {
651     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
652         c = 'x';
653     document.execCommand("InsertText", false, c);
654     debugForDumpAsText("execTypeCharacterCommand");
656 function typeCharacterCommand(c) {
657     if (commandDelay > 0) {
658         queueCommand(execTypeCharacterCommand.bind(execTypeCharacterCommand, c), commandCount * commandDelay);
659         commandCount++;
660     }
661     else {
662         execTypeCharacterCommand(c);
663     }
666 //-------------------------------------------------------------------------------------------------------
668 function execSelectAllCommand() {
669     document.execCommand("SelectAll");
671 function selectAllCommand() {
672     if (commandDelay > 0) {
673         queueCommand(execSelectAllCommand, commandCount * commandDelay);
674         commandCount++;
675     }
676     else {
677         execSelectAllCommand();
678     }
681 //-------------------------------------------------------------------------------------------------------
683 function execStrikethroughCommand() {
684     document.execCommand("Strikethrough");
685     debugForDumpAsText("execStrikethroughCommand");
687 function strikethroughCommand() {
688     if (commandDelay > 0) {
689         queueCommand(execStrikethroughCommand, commandCount * commandDelay);
690         commandCount++;
691     }
692     else {
693         execStrikethroughCommand();
694     }
697 //-------------------------------------------------------------------------------------------------------
699 function execUndoCommand() {
700     document.execCommand("Undo");
701     debugForDumpAsText("execUndoCommand");
703 function undoCommand() {
704     if (commandDelay > 0) {
705         queueCommand(execUndoCommand, commandCount * commandDelay);
706         commandCount++;
707     }
708     else {
709         execUndoCommand();
710     }
713 //-------------------------------------------------------------------------------------------------------
715 function execRedoCommand() {
716     document.execCommand("Redo");
717     debugForDumpAsText("execRedoCommand");
719 function redoCommand() {
720     if (commandDelay > 0) {
721         queueCommand(execRedoCommand, commandCount * commandDelay);
722         commandCount++;
723     }
724     else {
725         execRedoCommand();
726     }
729 //-------------------------------------------------------------------------------------------------------
731 function execChangeRootSize() {
732     document.getElementById("root").style.width = "600px";
734 function changeRootSize() {
735     if (commandDelay > 0) {
736         queueCommand(execChangeRootSize, commandCount * commandDelay);
737         commandCount++;
738     }
739     else {
740         execChangeRootSize();
741     }
744 //-------------------------------------------------------------------------------------------------------
746 function execCutCommand() {
747     document.execCommand("Cut");
748     debugForDumpAsText("execCutCommand");
750 function cutCommand() {
751     if (commandDelay > 0) {
752         queueCommand(execCutCommand, commandCount * commandDelay);
753         commandCount++;
754     }
755     else {
756         execCutCommand();
757     }
760 //-------------------------------------------------------------------------------------------------------
762 function execCopyCommand() {
763     document.execCommand("Copy");
764     debugForDumpAsText("execCopyCommand");
766 function copyCommand() {
767     if (commandDelay > 0) {
768         queueCommand(execCopyCommand, commandCount * commandDelay);
769         commandCount++;
770     }
771     else {
772         execCopyCommand();
773     }
776 //-------------------------------------------------------------------------------------------------------
778 function execPasteCommand() {
779     document.execCommand("Paste");
780     debugForDumpAsText("execPasteCommand");
782 function pasteCommand() {
783     if (commandDelay > 0) {
784         queueCommand(execPasteCommand, commandCount * commandDelay);
785         commandCount++;
786     }
787     else {
788         execPasteCommand();
789     }
792 //-------------------------------------------------------------------------------------------------------
794 function execCreateLinkCommand(url) {
795     document.execCommand("CreateLink", false, url);
796     debugForDumpAsText("execCreateLinkCommand");
798 function createLinkCommand(url) {
799     if (commandDelay > 0) {
800         queueCommand(execCreateLinkCommand.bind(execCreateLinkCommand, url), commandCount * commandDelay);
801         commandCount++;
802     } else
803         execCreateLinkCommand(url);
806 //-------------------------------------------------------------------------------------------------------
808 function execUnlinkCommand() {
809     document.execCommand("Unlink");
810     debugForDumpAsText("execUnlinkCommand");
812 function unlinkCommand() {
813     if (commandDelay > 0) {
814         queueCommand(execUnlinkCommand, commandCount * commandDelay);
815         commandCount++;
816     } else
817         execUnlinkCommand();
820 //-------------------------------------------------------------------------------------------------------
822 function execPasteAndMatchStyleCommand() {
823     document.execCommand("PasteAndMatchStyle");
824     debugForDumpAsText("execPasteAndMatchStyleCommand");
826 function pasteAndMatchStyleCommand() {
827     if (commandDelay > 0) {
828         queueCommand(execPasteAndMatchStyleCommand, commandCount * commandDelay);
829         commandCount++;
830     }
831     else {
832         execPasteAndMatchStyleCommand();
833     }
836 //-------------------------------------------------------------------------------------------------------
838 function execDeleteCommand() {
839     document.execCommand("Delete");
840     debugForDumpAsText("execDeleteCommand");
842 function deleteCommand() {
843     if (commandDelay > 0) {
844         queueCommand(execDeleteCommand, commandCount * commandDelay);
845         commandCount++;
846     }
847     else {
848         execDeleteCommand();
849     }
852 //-------------------------------------------------------------------------------------------------------
854 function execForwardDeleteCommand() {
855     document.execCommand("ForwardDelete");
856     debugForDumpAsText("execForwardDeleteCommand");
858 function forwardDeleteCommand() {
859     if (commandDelay > 0) {
860         queueCommand(execForwardDeleteCommand, commandCount * commandDelay);
861         commandCount++;
862     }
863     else {
864         execForwardDeleteCommand();
865     }
868 //-------------------------------------------------------------------------------------------------------
870 (function () {
871     var queue = [];
872     var i = 0;
873     var timer;
875     function queueCommand(callback) {
876         queue.push(callback);
877         if (!timer) {
878             if (window.testRunner)
879                 testRunner.waitUntilDone();
880             timer = setTimeout(runCommand, commandDelay);
881         }
882     }
884     function runCommand() {
885         queue[i]();
886         i++;
887         if (i < queue.length)
888             setTimeout(runCommand, commandDelay);
889         else if (window.testRunner)
890             testRunner.notifyDone();
891     }
892     
893     window.queueCommand = queueCommand;
894 })();
896 function focusOnFirstTextInTestElementIfExists() {
897     var elem = document.getElementById("test");
898     var selection = window.getSelection();
899     if (elem) {
900         var traverse = function (node, offset, condition) {
901             var obj = condition(node, offset);
902             if (obj)
903                 return obj;
905             var children = node.childNodes;
906             var len = children.length;
907             for (var i = 0; i < len; i++) {
908                 var child = children[i];
909                 obj = traverse(child, i, condition);
910                 if (obj)
911                     return obj;
912             }
913             return null;
914         }
916         var firstVisiblePosition = traverse(elem, 0, function (node, offset) {
917             if (node.nodeName == '#text') {
918                 offset = 0;
919                 while (offset < node.textContent.length && node.textContent[offset] == '\n')
920                     offset++;
921                 return { 'node': node, 'offset': offset };
922             }
924             if (node.nodeName == 'BR' || node.nodeName == 'IMG')
925                 return { 'node': node.parentNode, 'offset': offset };
927             return null;
928         });
930         if (firstVisiblePosition)
931             selection.collapse(firstVisiblePosition.node, firstVisiblePosition.offset);
932         else
933             selection.collapse(elem, 0);
934     } else {
935         selection.removeAllRanges();
936     }
939 function runEditingTest() {
940     if (window.testRunner)
941         testRunner.dumpEditingCallbacks();
943     focusOnFirstTextInTestElementIfExists();
945     editingTest();
948 var dumpAsText = false;
949 var elementsForDumpingMarkupList = [document.createElement('ol')];
951 function runDumpAsTextEditingTest(enableCallbacks) {
952     if (window.testRunner) {
953          testRunner.dumpAsText();
954          if (enableCallbacks)
955             testRunner.dumpEditingCallbacks();
956      }
958     dumpAsText = true;
960     focusOnFirstTextInTestElementIfExists();
962     editingTest();
964     for (var i = 0; i < elementsForDumpingMarkupList.length; i++)
965         document.body.appendChild(elementsForDumpingMarkupList[i]);
968 function debugForDumpAsText(name) {
969     if (dumpAsText && document.getElementById("root")) {
970         var newItem = document.createElement('li');
971         newItem.appendChild(document.createTextNode(name+": "+document.getElementById("root").innerHTML));
972         elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].appendChild(newItem);
973     }
976 function startNewMarkupGroup(label) {
977     if (!elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].hasChildNodes())
978         elementsForDumpingMarkupList.pop();
979     elementsForDumpingMarkupList.push(document.createElement('br'));
980     elementsForDumpingMarkupList.push(document.createTextNode(label));
981     elementsForDumpingMarkupList.push(document.createElement('ol'));
984 //-------------------------------------------------------------------------------------------------------
987 function execBackColorCommand() {
988     document.execCommand("BackColor", false, "Chartreuse");
989     debugForDumpAsText('execBackColorCommand');
991 function backColorCommand() {
992     if (commandDelay > 0) {
993         queueCommand(execBackColorCommand, commandCount * commandDelay);
994         commandCount++;
995     }
996     else {
997         execBackColorCommand();
998     }
1002 function execForeColorCommand(color) {
1003     document.execCommand("ForeColor", false, color);
1004     debugForDumpAsText('execForeColorCommand');
1006 function foreColorCommand(color) {
1007     if (commandDelay > 0) {
1008         queueCommand(execForeColorCommand.bind(execForeColorCommand, color), commandCount * commandDelay);
1009         commandCount++;
1010     } else
1011         execForeColorCommand(color);
1014 //-------------------------------------------------------------------------------------------------------
1017 function runCommand(command, arg1, arg2) {
1018     document.execCommand(command,arg1,arg2);
1021 function executeCommand(command,arg1,arg2) {
1022     if (commandDelay > 0) {
1023         queueCommand(runCommand, commandCount * commandDelay);
1024         commandCount++;
1025     }
1026     else {
1027         runCommand(command,arg1,arg2);
1028     }