blob: ec3221d3d75fe837361cd257947a68d33b8c2786 [file] [log] [blame]
kocienda495c3032004-04-06 15:21:34 +00001//-------------------------------------------------------------------------------------------------------
2// Java script library to run editing layout tests
3
4var commandCount = 1;
5var commandDelay = window.location.search.substring(1);
6if (commandDelay == '')
7 commandDelay = 0;
8var selection = window.getSelection();
9
10//-------------------------------------------------------------------------------------------------------
11
justing406880a2006-05-03 03:17:55 +000012function execSetSelectionCommand(sn, so, en, eo) {
13 window.getSelection().setBaseAndExtent(sn, so, en, eo);
14}
simon.fraser@apple.com03656032009-11-23 23:30:31 +000015
16// Args are startNode, startOffset, endNode, endOffset
justing406880a2006-05-03 03:17:55 +000017function setSelectionCommand(sn, so, en, eo) {
18 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +000019 queueCommand(execSetSelectionCommand.bind(execSetSelectionCommand, sn, so, en, eo), commandCount * commandDelay);
justing406880a2006-05-03 03:17:55 +000020 commandCount++;
21 } else
22 execSetSelectionCommand(sn, so, en, eo);
23}
24
25//-------------------------------------------------------------------------------------------------------
26
harrison86554792005-05-26 20:30:12 +000027function execTransposeCharactersCommand() {
28 document.execCommand("Transpose");
29}
30function transposeCharactersCommand() {
31 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +000032 queueCommand(execTransposeCharactersCommand, commandCount * commandDelay);
harrison86554792005-05-26 20:30:12 +000033 commandCount++;
34 }
35 else {
36 execTransposeCharactersCommand();
37 }
38}
39
40//-------------------------------------------------------------------------------------------------------
41
leviw@chromium.orgbd727b82011-01-21 01:21:11 +000042function execMoveSelectionLeftByCharacterCommand() {
43 selection.modify("move", "left", "character");
44}
45function moveSelectionLeftByCharacterCommand() {
46 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +000047 queueCommand(execMoveSelectionLeftByCharacterCommand, commandCount * commandDelay);
leviw@chromium.orgbd727b82011-01-21 01:21:11 +000048 commandCount++;
49 }
50 else {
51 execMoveSelectionLeftByCharacterCommand();
52 }
53}
54
55//-------------------------------------------------------------------------------------------------------
56
57function execMoveSelectionRightByCharacterCommand() {
58 selection.modify("move", "Right", "character");
59}
60function moveSelectionRightByCharacterCommand() {
61 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +000062 queueCommand(execMoveSelectionRightByCharacterCommand, commandCount * commandDelay);
leviw@chromium.orgbd727b82011-01-21 01:21:11 +000063 commandCount++;
64 }
65 else {
66 execMoveSelectionRightByCharacterCommand();
67 }
68}
69
70//-------------------------------------------------------------------------------------------------------
71
72function execExtendSelectionLeftByCharacterCommand() {
73 selection.modify("extend", "left", "character");
74}
75function extendSelectionLeftByCharacterCommand() {
76 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +000077 queueCommand(execExtendSelectionLeftByCharacterCommand, commandCount * commandDelay);
leviw@chromium.orgbd727b82011-01-21 01:21:11 +000078 commandCount++;
79 }
80 else {
81 execExtendSelectionLeftByCharacterCommand();
82 }
83}
84
85//-------------------------------------------------------------------------------------------------------
86
87function execExtendSelectionRightByCharacterCommand() {
88 selection.modify("extend", "Right", "character");
89}
90function extendSelectionRightByCharacterCommand() {
91 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +000092 queueCommand(execExtendSelectionRightByCharacterCommand, commandCount * commandDelay);
leviw@chromium.orgbd727b82011-01-21 01:21:11 +000093 commandCount++;
94 }
95 else {
96 execExtendSelectionRightByCharacterCommand();
97 }
98}
99
100//-------------------------------------------------------------------------------------------------------
101
kocienda495c3032004-04-06 15:21:34 +0000102function execMoveSelectionForwardByCharacterCommand() {
103 selection.modify("move", "forward", "character");
104}
105function moveSelectionForwardByCharacterCommand() {
106 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000107 queueCommand(execMoveSelectionForwardByCharacterCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000108 commandCount++;
109 }
110 else {
111 execMoveSelectionForwardByCharacterCommand();
112 }
113}
114
115//-------------------------------------------------------------------------------------------------------
116
117function execExtendSelectionForwardByCharacterCommand() {
118 selection.modify("extend", "forward", "character");
119}
120function extendSelectionForwardByCharacterCommand() {
121 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000122 queueCommand(execExtendSelectionForwardByCharacterCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000123 commandCount++;
124 }
125 else {
126 execExtendSelectionForwardByCharacterCommand();
127 }
128}
129
130//-------------------------------------------------------------------------------------------------------
131
kocienda0c3df172004-09-13 18:39:31 +0000132function execMoveSelectionForwardByWordCommand() {
133 selection.modify("move", "forward", "word");
134}
135function moveSelectionForwardByWordCommand() {
136 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000137 queueCommand(execMoveSelectionForwardByWordCommand, commandCount * commandDelay);
kocienda0c3df172004-09-13 18:39:31 +0000138 commandCount++;
139 }
140 else {
141 execMoveSelectionForwardByWordCommand();
142 }
143}
144
145//-------------------------------------------------------------------------------------------------------
146
147function execExtendSelectionForwardByWordCommand() {
148 selection.modify("extend", "forward", "word");
149}
150function extendSelectionForwardByWordCommand() {
151 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000152 queueCommand(execExtendSelectionForwardByWordCommand, commandCount * commandDelay);
kocienda0c3df172004-09-13 18:39:31 +0000153 commandCount++;
154 }
155 else {
156 execExtendSelectionForwardByWordCommand();
157 }
158}
159
160//-------------------------------------------------------------------------------------------------------
161
harrisonf0576d82006-04-13 00:21:46 +0000162function execMoveSelectionForwardBySentenceCommand() {
163 selection.modify("move", "forward", "sentence");
164}
165function moveSelectionForwardBySentenceCommand() {
166 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000167 queueCommand(execMoveSelectionForwardBySentenceCommand, commandCount * commandDelay);
harrisonf0576d82006-04-13 00:21:46 +0000168 commandCount++;
169 }
170 else {
171 execMoveSelectionForwardBySentenceCommand();
172 }
173}
174
175//-------------------------------------------------------------------------------------------------------
176
177function execExtendSelectionForwardBySentenceCommand() {
178 selection.modify("extend", "forward", "sentence");
179}
180function extendSelectionForwardBySentenceCommand() {
181 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000182 queueCommand(execExtendSelectionForwardBySentenceCommand, commandCount * commandDelay);
harrisonf0576d82006-04-13 00:21:46 +0000183 commandCount++;
184 }
185 else {
186 execExtendSelectionForwardBySentenceCommand();
187 }
188}
189
190//-------------------------------------------------------------------------------------------------------
191
kociendae300a4c2004-08-31 15:41:34 +0000192function execMoveSelectionForwardByLineCommand() {
193 selection.modify("move", "forward", "line");
kdeckerfd91e242004-07-14 00:38:38 +0000194}
kociendae300a4c2004-08-31 15:41:34 +0000195function moveSelectionForwardByLineCommand() {
kdeckerfd91e242004-07-14 00:38:38 +0000196 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000197 queueCommand(execMoveSelectionForwardByLineCommand, commandCount * commandDelay);
kdeckerfd91e242004-07-14 00:38:38 +0000198 commandCount++;
199 }
200 else {
kociendae300a4c2004-08-31 15:41:34 +0000201 execMoveSelectionForwardByLineCommand();
kdeckerfd91e242004-07-14 00:38:38 +0000202 }
203}
kociendae300a4c2004-08-31 15:41:34 +0000204
205//-------------------------------------------------------------------------------------------------------
206
207function execExtendSelectionForwardByLineCommand() {
208 selection.modify("extend", "forward", "line");
209}
210function extendSelectionForwardByLineCommand() {
211 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000212 queueCommand(execExtendSelectionForwardByLineCommand, commandCount * commandDelay);
kociendae300a4c2004-08-31 15:41:34 +0000213 commandCount++;
214 }
215 else {
216 execExtendSelectionForwardByLineCommand();
217 }
218}
219
kdeckerfd91e242004-07-14 00:38:38 +0000220//-------------------------------------------------------------------------------------------------------
221
ojan@chromium.org0037bb12010-02-18 19:38:14 +0000222function execMoveSelectionForwardByLineBoundaryCommand() {
223 selection.modify("move", "forward", "lineBoundary");
224}
225function moveSelectionForwardByLineBoundaryCommand() {
226 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000227 queueCommand(execMoveSelectionForwardByLineBoundaryCommand, commandCount * commandDelay);
ojan@chromium.org0037bb12010-02-18 19:38:14 +0000228 commandCount++;
229 }
230 else {
231 execMoveSelectionForwardByLineBoundaryCommand();
232 }
233}
234
235//-------------------------------------------------------------------------------------------------------
236
237function execExtendSelectionForwardByLineBoundaryCommand() {
238 selection.modify("extend", "forward", "lineBoundary");
239}
240function extendSelectionForwardByLineBoundaryCommand() {
241 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000242 queueCommand(execExtendSelectionForwardByLineBoundaryCommand, commandCount * commandDelay);
ojan@chromium.org0037bb12010-02-18 19:38:14 +0000243 commandCount++;
244 }
245 else {
246 execExtendSelectionForwardByLineBoundaryCommand();
247 }
248}
249
250//-------------------------------------------------------------------------------------------------------
251
kocienda495c3032004-04-06 15:21:34 +0000252function execMoveSelectionBackwardByCharacterCommand() {
253 selection.modify("move", "backward", "character");
254}
255function moveSelectionBackwardByCharacterCommand() {
256 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000257 queueCommand(execMoveSelectionBackwardByCharacterCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000258 commandCount++;
259 }
260 else {
261 execMoveSelectionBackwardByCharacterCommand();
262 }
263}
264
265//-------------------------------------------------------------------------------------------------------
266
267function execExtendSelectionBackwardByCharacterCommand() {
268 selection.modify("extend", "backward", "character");
269}
270function extendSelectionBackwardByCharacterCommand() {
271 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000272 queueCommand(execExtendSelectionBackwardByCharacterCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000273 commandCount++;
274 }
275 else {
276 execExtendSelectionBackwardByCharacterCommand();
277 }
278}
279
280//-------------------------------------------------------------------------------------------------------
281
kocienda0c3df172004-09-13 18:39:31 +0000282function execMoveSelectionBackwardByWordCommand() {
283 selection.modify("move", "backward", "word");
284}
285function moveSelectionBackwardByWordCommand() {
286 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000287 queueCommand(execMoveSelectionBackwardByWordCommand, commandCount * commandDelay);
kocienda0c3df172004-09-13 18:39:31 +0000288 commandCount++;
289 }
290 else {
291 execMoveSelectionBackwardByWordCommand();
292 }
293}
294
295//-------------------------------------------------------------------------------------------------------
296
297function execExtendSelectionBackwardByWordCommand() {
298 selection.modify("extend", "backward", "word");
299}
300function extendSelectionBackwardByWordCommand() {
301 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000302 queueCommand(execExtendSelectionBackwardByWordCommand, commandCount * commandDelay);
kocienda0c3df172004-09-13 18:39:31 +0000303 commandCount++;
304 }
305 else {
306 execExtendSelectionBackwardByWordCommand();
307 }
308}
309
310//-------------------------------------------------------------------------------------------------------
311
harrisonf0576d82006-04-13 00:21:46 +0000312function execMoveSelectionBackwardBySentenceCommand() {
313 selection.modify("move", "backward", "sentence");
314}
315function moveSelectionBackwardBySentenceCommand() {
316 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000317 queueCommand(execMoveSelectionBackwardBySentenceCommand, commandCount * commandDelay);
harrisonf0576d82006-04-13 00:21:46 +0000318 commandCount++;
319 }
320 else {
321 execMoveSelectionBackwardBySentenceCommand();
322 }
323}
324
325//-------------------------------------------------------------------------------------------------------
326
327function execExtendSelectionBackwardBySentenceCommand() {
328 selection.modify("extend", "backward", "sentence");
329}
330function extendSelectionBackwardBySentenceCommand() {
331 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000332 queueCommand(execExtendSelectionBackwardBySentenceCommand, commandCount * commandDelay);
harrisonf0576d82006-04-13 00:21:46 +0000333 commandCount++;
334 }
335 else {
336 execExtendSelectionBackwardBySentenceCommand();
337 }
338}
339
340//-------------------------------------------------------------------------------------------------------
341
kociendae300a4c2004-08-31 15:41:34 +0000342function execMoveSelectionBackwardByLineCommand() {
343 selection.modify("move", "backward", "line");
344}
345function moveSelectionBackwardByLineCommand() {
346 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000347 queueCommand(execMoveSelectionBackwardByLineCommand, commandCount * commandDelay);
kociendae300a4c2004-08-31 15:41:34 +0000348 commandCount++;
349 }
350 else {
351 execMoveSelectionBackwardByLineCommand();
352 }
353}
354
355//-------------------------------------------------------------------------------------------------------
356
357function execExtendSelectionBackwardByLineCommand() {
358 selection.modify("extend", "backward", "line");
359}
360function extendSelectionBackwardByLineCommand() {
361 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000362 queueCommand(execExtendSelectionBackwardByLineCommand, commandCount * commandDelay);
kociendae300a4c2004-08-31 15:41:34 +0000363 commandCount++;
364 }
365 else {
366 execExtendSelectionBackwardByLineCommand();
367 }
368}
369
370//-------------------------------------------------------------------------------------------------------
371
ojan@chromium.org0037bb12010-02-18 19:38:14 +0000372function execExtendSelectionBackwardByLineBoundaryCommand() {
373 selection.modify("extend", "backward", "lineBoundary");
374}
375function extendSelectionBackwardByLineBoundaryCommand() {
376 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000377 queueCommand(execExtendSelectionBackwardByLineBoundaryCommand, commandCount * commandDelay);
ojan@chromium.org0037bb12010-02-18 19:38:14 +0000378 commandCount++;
379 }
380 else {
381 execExtendSelectionBackwardByLineBoundaryCommand();
382 }
383}
384
385//-------------------------------------------------------------------------------------------------------
386
387function execMoveSelectionBackwardByLineBoundaryCommand() {
388 selection.modify("move", "backward", "lineBoundary");
389}
390function moveSelectionBackwardByLineBoundaryCommand() {
391 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000392 queueCommand(execMoveSelectionBackwardByLineBoundaryCommand, commandCount * commandDelay);
ojan@chromium.org0037bb12010-02-18 19:38:14 +0000393 commandCount++;
394 }
395 else {
396 execMoveSelectionBackwardByLineBoundaryCommand();
397 }
398}
399
400//-------------------------------------------------------------------------------------------------------
401
ojan@chromium.org0b530eb2010-03-12 18:18:40 +0000402function doubleClick(x, y) {
403 eventSender.mouseMoveTo(x, y);
404 eventSender.mouseDown();
405 eventSender.mouseUp();
406 eventSender.mouseDown();
407 eventSender.mouseUp();
408}
409
410function 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);
415}
416
417//-------------------------------------------------------------------------------------------------------
418
kocienda259ced72004-06-11 18:33:50 +0000419function execBoldCommand() {
420 document.execCommand("Bold");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000421 debugForDumpAsText("execBoldCommand");
kocienda259ced72004-06-11 18:33:50 +0000422}
423function boldCommand() {
424 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000425 queueCommand(execBoldCommand, commandCount * commandDelay);
kocienda259ced72004-06-11 18:33:50 +0000426 commandCount++;
427 }
428 else {
429 execBoldCommand();
430 }
431}
432
kocienda10bf0db2005-01-17 22:18:47 +0000433//-------------------------------------------------------------------------------------------------------
434
mjse99cfcb2005-01-28 01:13:07 +0000435function execUnderlineCommand() {
436 document.execCommand("Underline");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000437 debugForDumpAsText("execUnderlineCommand");
mjse99cfcb2005-01-28 01:13:07 +0000438}
439function underlineCommand() {
440 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000441 queueCommand(execUnderlineCommand, commandCount * commandDelay);
mjse99cfcb2005-01-28 01:13:07 +0000442 commandCount++;
443 }
444 else {
445 execUnderlineCommand();
446 }
447}
448
449//-------------------------------------------------------------------------------------------------------
450
kocienda10bf0db2005-01-17 22:18:47 +0000451function execFontNameCommand() {
452 document.execCommand("FontName", false, "Courier");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000453 debugForDumpAsText("execFontNameCommand");
kocienda10bf0db2005-01-17 22:18:47 +0000454}
455function fontNameCommand() {
456 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000457 queueCommand(execFontNameCommand, commandCount * commandDelay);
kocienda10bf0db2005-01-17 22:18:47 +0000458 commandCount++;
459 }
460 else {
461 execFontNameCommand();
462 }
463}
464
465//-------------------------------------------------------------------------------------------------------
466
467function execFontSizeCommand(s) {
468 if (arguments.length == 0 || s == undefined || s.length == 0)
469 s = '12px';
470 document.execCommand("FontSize", false, s);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000471 debugForDumpAsText("execFontSizeCommand");
kocienda10bf0db2005-01-17 22:18:47 +0000472}
473function fontSizeCommand(s) {
474 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000475 queueCommand(execFontSizeCommand, commandCount * commandDelay, s);
kocienda10bf0db2005-01-17 22:18:47 +0000476 commandCount++;
477 }
478 else {
479 execFontSizeCommand(s);
480 }
481}
482
483//-------------------------------------------------------------------------------------------------------
484
485function execFontSizeDeltaCommand(s) {
486 if (arguments.length == 0 || s == undefined || s.length == 0)
487 s = '1px';
488 document.execCommand("FontSizeDelta", false, s);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000489 debugForDumpAsText("execFontSizeDeltaCommand");
kocienda10bf0db2005-01-17 22:18:47 +0000490}
491function fontSizeDeltaCommand(s) {
492 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000493 queueCommand(execFontSizeDeltaCommand.bind(execFontSizeDeltaCommand, s), commandCount * commandDelay);
kocienda10bf0db2005-01-17 22:18:47 +0000494 commandCount++;
495 }
496 else {
497 execFontSizeDeltaCommand(s);
498 }
499}
kdeckerfd91e242004-07-14 00:38:38 +0000500
kocienda259ced72004-06-11 18:33:50 +0000501//-------------------------------------------------------------------------------------------------------
502
kocienda6a844e52004-08-31 15:02:27 +0000503function execItalicCommand() {
504 document.execCommand("Italic");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000505 debugForDumpAsText("execItalicCommand");
kocienda6a844e52004-08-31 15:02:27 +0000506}
507function italicCommand() {
508 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000509 queueCommand(execItalicCommand, commandCount * commandDelay);
kocienda6a844e52004-08-31 15:02:27 +0000510 commandCount++;
511 }
512 else {
513 execItalicCommand();
514 }
515}
516
517
518//-------------------------------------------------------------------------------------------------------
519
kocienda2b62edb2004-11-01 17:56:33 +0000520function execJustifyCenterCommand() {
521 document.execCommand("JustifyCenter");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000522 debugForDumpAsText("execJustifyCenterCommand");
kocienda2b62edb2004-11-01 17:56:33 +0000523}
524function justifyCenterCommand() {
525 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000526 queueCommand(execJustifyCenterCommand, commandCount * commandDelay);
kocienda2b62edb2004-11-01 17:56:33 +0000527 commandCount++;
528 }
529 else {
530 execJustifyCenterCommand();
531 }
532}
533
534
535//-------------------------------------------------------------------------------------------------------
536
537function execJustifyLeftCommand() {
538 document.execCommand("JustifyLeft");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000539 debugForDumpAsText("execJustifyLeftCommand");
kocienda2b62edb2004-11-01 17:56:33 +0000540}
541function justifyLeftCommand() {
542 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000543 queueCommand(execJustifyLeftCommand, commandCount * commandDelay);
kocienda2b62edb2004-11-01 17:56:33 +0000544 commandCount++;
545 }
546 else {
547 execJustifyLeftCommand();
548 }
549}
550
551
552//-------------------------------------------------------------------------------------------------------
553
554function execJustifyRightCommand() {
555 document.execCommand("JustifyRight");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000556 debugForDumpAsText("execJustifyRightCommand");
kocienda2b62edb2004-11-01 17:56:33 +0000557}
558function justifyRightCommand() {
559 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000560 queueCommand(execJustifyRightCommand, commandCount * commandDelay);
kocienda2b62edb2004-11-01 17:56:33 +0000561 commandCount++;
562 }
563 else {
564 execJustifyRightCommand();
565 }
566}
567
kocienda2b62edb2004-11-01 17:56:33 +0000568//-------------------------------------------------------------------------------------------------------
569
justingd7ecdb82006-03-01 02:54:35 +0000570function execInsertHTMLCommand(html) {
571 document.execCommand("InsertHTML", false, html);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000572 debugForDumpAsText("execInsertHTMLCommand");
justingd7ecdb82006-03-01 02:54:35 +0000573}
574function insertHTMLCommand(html) {
575 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000576 queueCommand(execInsertHTMLCommand.bind(execInsertHTMLCommand, html), commandCount * commandDelay);
justingd7ecdb82006-03-01 02:54:35 +0000577 commandCount++;
578 }
579 else {
580 execInsertHTMLCommand(html);
581 }
582}
583
584//-------------------------------------------------------------------------------------------------------
585
justingafa34c92006-03-08 23:07:07 +0000586function execInsertImageCommand(imgSrc) {
587 document.execCommand("InsertImage", false, imgSrc);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000588 debugForDumpAsText("execInsertImageCommand");
justingafa34c92006-03-08 23:07:07 +0000589}
590function insertImageCommand(imgSrc) {
591 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000592 queueCommand(execInsertImageCommand.bind(execInsertImageCommand, imgSrc), commandCount * commandDelay);
justingafa34c92006-03-08 23:07:07 +0000593 commandCount++;
594 }
595 else {
596 execInsertImageCommand(imgSrc);
597 }
598}
599
600//-------------------------------------------------------------------------------------------------------
601
kocienda4b4f21f2004-12-03 17:31:30 +0000602function execInsertLineBreakCommand() {
603 document.execCommand("InsertLineBreak");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000604 debugForDumpAsText("execInsertLineBreakCommand");
kocienda259ced72004-06-11 18:33:50 +0000605}
kocienda4b4f21f2004-12-03 17:31:30 +0000606function insertLineBreakCommand() {
kocienda259ced72004-06-11 18:33:50 +0000607 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000608 queueCommand(execInsertLineBreakCommand, commandCount * commandDelay);
kocienda259ced72004-06-11 18:33:50 +0000609 commandCount++;
610 }
611 else {
kocienda4b4f21f2004-12-03 17:31:30 +0000612 execInsertLineBreakCommand();
kocienda259ced72004-06-11 18:33:50 +0000613 }
614}
615
616//-------------------------------------------------------------------------------------------------------
kocienda5f52bcb2004-12-06 17:39:44 +0000617
618function execInsertParagraphCommand() {
619 document.execCommand("InsertParagraph");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000620 debugForDumpAsText("execInsertParagraphCommand");
kocienda5f52bcb2004-12-06 17:39:44 +0000621}
622function insertParagraphCommand() {
623 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000624 queueCommand(execInsertParagraphCommand, commandCount * commandDelay);
kocienda5f52bcb2004-12-06 17:39:44 +0000625 commandCount++;
626 }
627 else {
628 execInsertParagraphCommand();
629 }
630}
631
632//-------------------------------------------------------------------------------------------------------
kocienda259ced72004-06-11 18:33:50 +0000633
harrisondc2b84a2005-11-03 18:16:30 +0000634function execInsertNewlineInQuotedContentCommand() {
635 document.execCommand("InsertNewlineInQuotedContent");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000636 debugForDumpAsText("execInsertNewlineInQuotedContentCommand");
harrisondc2b84a2005-11-03 18:16:30 +0000637}
638function insertNewlineInQuotedContentCommand() {
639 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000640 queueCommand(execInsertNewlineInQuotedContentCommand, commandCount * commandDelay);
harrisondc2b84a2005-11-03 18:16:30 +0000641 commandCount++;
642 }
643 else {
644 execInsertNewlineInQuotedContentCommand();
645 }
646}
647
648//-------------------------------------------------------------------------------------------------------
649
kocienda46aa5152004-08-31 15:14:57 +0000650function execTypeCharacterCommand(c) {
651 if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
652 c = 'x';
653 document.execCommand("InsertText", false, c);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000654 debugForDumpAsText("execTypeCharacterCommand");
kocienda495c3032004-04-06 15:21:34 +0000655}
kocienda46aa5152004-08-31 15:14:57 +0000656function typeCharacterCommand(c) {
kocienda495c3032004-04-06 15:21:34 +0000657 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000658 queueCommand(execTypeCharacterCommand.bind(execTypeCharacterCommand, c), commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000659 commandCount++;
660 }
661 else {
kocienda46aa5152004-08-31 15:14:57 +0000662 execTypeCharacterCommand(c);
kocienda495c3032004-04-06 15:21:34 +0000663 }
664}
665
666//-------------------------------------------------------------------------------------------------------
667
668function execSelectAllCommand() {
669 document.execCommand("SelectAll");
670}
671function selectAllCommand() {
672 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000673 queueCommand(execSelectAllCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000674 commandCount++;
675 }
676 else {
677 execSelectAllCommand();
678 }
679}
680
681//-------------------------------------------------------------------------------------------------------
682
anderscaf734ebd2006-01-21 20:15:17 +0000683function execStrikethroughCommand() {
684 document.execCommand("Strikethrough");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000685 debugForDumpAsText("execStrikethroughCommand");
anderscaf734ebd2006-01-21 20:15:17 +0000686}
andersca5d2265462006-01-21 21:20:31 +0000687function strikethroughCommand() {
anderscaf734ebd2006-01-21 20:15:17 +0000688 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000689 queueCommand(execStrikethroughCommand, commandCount * commandDelay);
anderscaf734ebd2006-01-21 20:15:17 +0000690 commandCount++;
691 }
692 else {
693 execStrikethroughCommand();
694 }
695}
696
697//-------------------------------------------------------------------------------------------------------
698
kocienda495c3032004-04-06 15:21:34 +0000699function execUndoCommand() {
700 document.execCommand("Undo");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000701 debugForDumpAsText("execUndoCommand");
kocienda495c3032004-04-06 15:21:34 +0000702}
703function undoCommand() {
704 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000705 queueCommand(execUndoCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000706 commandCount++;
707 }
708 else {
709 execUndoCommand();
710 }
711}
712
713//-------------------------------------------------------------------------------------------------------
714
715function execRedoCommand() {
716 document.execCommand("Redo");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000717 debugForDumpAsText("execRedoCommand");
kocienda495c3032004-04-06 15:21:34 +0000718}
719function redoCommand() {
720 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000721 queueCommand(execRedoCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000722 commandCount++;
723 }
724 else {
725 execRedoCommand();
726 }
727}
728
729//-------------------------------------------------------------------------------------------------------
730
731function execChangeRootSize() {
732 document.getElementById("root").style.width = "600px";
733}
734function changeRootSize() {
735 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000736 queueCommand(execChangeRootSize, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000737 commandCount++;
738 }
739 else {
740 execChangeRootSize();
741 }
742}
743
744//-------------------------------------------------------------------------------------------------------
745
kocienda69706492004-04-12 18:41:51 +0000746function execCutCommand() {
747 document.execCommand("Cut");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000748 debugForDumpAsText("execCutCommand");
kocienda69706492004-04-12 18:41:51 +0000749}
750function cutCommand() {
751 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000752 queueCommand(execCutCommand, commandCount * commandDelay);
kocienda69706492004-04-12 18:41:51 +0000753 commandCount++;
754 }
755 else {
756 execCutCommand();
757 }
758}
759
760//-------------------------------------------------------------------------------------------------------
761
762function execCopyCommand() {
763 document.execCommand("Copy");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000764 debugForDumpAsText("execCopyCommand");
kocienda69706492004-04-12 18:41:51 +0000765}
766function copyCommand() {
767 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000768 queueCommand(execCopyCommand, commandCount * commandDelay);
kocienda69706492004-04-12 18:41:51 +0000769 commandCount++;
770 }
771 else {
772 execCopyCommand();
773 }
774}
775
776//-------------------------------------------------------------------------------------------------------
777
778function execPasteCommand() {
779 document.execCommand("Paste");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000780 debugForDumpAsText("execPasteCommand");
kocienda69706492004-04-12 18:41:51 +0000781}
782function pasteCommand() {
783 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000784 queueCommand(execPasteCommand, commandCount * commandDelay);
kocienda69706492004-04-12 18:41:51 +0000785 commandCount++;
786 }
787 else {
788 execPasteCommand();
789 }
790}
791
792//-------------------------------------------------------------------------------------------------------
793
justing75ac4fc2006-03-15 07:01:21 +0000794function execCreateLinkCommand(url) {
795 document.execCommand("CreateLink", false, url);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000796 debugForDumpAsText("execCreateLinkCommand");
justing75ac4fc2006-03-15 07:01:21 +0000797}
798function createLinkCommand(url) {
799 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000800 queueCommand(execCreateLinkCommand.bind(execCreateLinkCommand, url), commandCount * commandDelay);
justing75ac4fc2006-03-15 07:01:21 +0000801 commandCount++;
justingf6acc032006-03-25 10:17:39 +0000802 } else
justing75ac4fc2006-03-15 07:01:21 +0000803 execCreateLinkCommand(url);
justingf6acc032006-03-25 10:17:39 +0000804}
805
806//-------------------------------------------------------------------------------------------------------
807
808function execUnlinkCommand() {
809 document.execCommand("Unlink");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000810 debugForDumpAsText("execUnlinkCommand");
justingf6acc032006-03-25 10:17:39 +0000811}
812function unlinkCommand() {
813 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000814 queueCommand(execUnlinkCommand, commandCount * commandDelay);
justingf6acc032006-03-25 10:17:39 +0000815 commandCount++;
816 } else
817 execUnlinkCommand();
justing75ac4fc2006-03-15 07:01:21 +0000818}
819
820//-------------------------------------------------------------------------------------------------------
821
cblu4fb6bc52005-02-23 02:34:08 +0000822function execPasteAndMatchStyleCommand() {
823 document.execCommand("PasteAndMatchStyle");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000824 debugForDumpAsText("execPasteAndMatchStyleCommand");
cblu4fb6bc52005-02-23 02:34:08 +0000825}
826function pasteAndMatchStyleCommand() {
827 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000828 queueCommand(execPasteAndMatchStyleCommand, commandCount * commandDelay);
cblu4fb6bc52005-02-23 02:34:08 +0000829 commandCount++;
830 }
831 else {
832 execPasteAndMatchStyleCommand();
833 }
834}
835
836//-------------------------------------------------------------------------------------------------------
837
kocienda495c3032004-04-06 15:21:34 +0000838function execDeleteCommand() {
839 document.execCommand("Delete");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000840 debugForDumpAsText("execDeleteCommand");
kocienda495c3032004-04-06 15:21:34 +0000841}
842function deleteCommand() {
843 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000844 queueCommand(execDeleteCommand, commandCount * commandDelay);
kocienda495c3032004-04-06 15:21:34 +0000845 commandCount++;
846 }
847 else {
848 execDeleteCommand();
849 }
850}
851
852//-------------------------------------------------------------------------------------------------------
853
kociendafe000852005-01-28 00:43:57 +0000854function execForwardDeleteCommand() {
855 document.execCommand("ForwardDelete");
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000856 debugForDumpAsText("execForwardDeleteCommand");
kociendafe000852005-01-28 00:43:57 +0000857}
858function forwardDeleteCommand() {
859 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000860 queueCommand(execForwardDeleteCommand, commandCount * commandDelay);
kociendafe000852005-01-28 00:43:57 +0000861 commandCount++;
862 }
863 else {
864 execForwardDeleteCommand();
865 }
866}
867
868//-------------------------------------------------------------------------------------------------------
869
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000870(function () {
871 var queue = [];
872 var i = 0;
873 var timer;
874
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 }
883
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})();
895
kocienda495c3032004-04-06 15:21:34 +0000896function runEditingTest() {
timothy_horton@apple.com2d191402017-01-04 03:13:22 +0000897 runEditingTestWithCallbackLogging(true);
898}
899
900function runEditingTestWithCallbackLogging(enableCallbackLogging) {
901 if (window.testRunner && enableCallbackLogging)
rniwa@webkit.org14f6b5b2012-06-13 08:51:53 +0000902 testRunner.dumpEditingCallbacks();
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000903
kocienda495c3032004-04-06 15:21:34 +0000904 var elem = document.getElementById("test");
905 var selection = window.getSelection();
906 selection.setPosition(elem, 0);
907 editingTest();
908}
909
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000910var dumpAsText = false;
commit-queue@webkit.org92964672013-07-31 04:55:02 +0000911var elementsForDumpingMarkupList = [document.createElement('ol')];
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000912
913function runDumpAsTextEditingTest(enableCallbacks) {
rniwa@webkit.org14f6b5b2012-06-13 08:51:53 +0000914 if (window.testRunner) {
915 testRunner.dumpAsText();
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000916 if (enableCallbacks)
rniwa@webkit.org14f6b5b2012-06-13 08:51:53 +0000917 testRunner.dumpEditingCallbacks();
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000918 }
919
920 dumpAsText = true;
921
922 var elem = document.getElementById("test");
923 var selection = window.getSelection();
924 selection.setPosition(elem, 0);
925 editingTest();
926
commit-queue@webkit.org92964672013-07-31 04:55:02 +0000927 for (var i = 0; i < elementsForDumpingMarkupList.length; i++)
928 document.body.appendChild(elementsForDumpingMarkupList[i]);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000929}
930
931function debugForDumpAsText(name) {
932 if (dumpAsText && document.getElementById("root")) {
933 var newItem = document.createElement('li');
934 newItem.appendChild(document.createTextNode(name+": "+document.getElementById("root").innerHTML));
commit-queue@webkit.org92964672013-07-31 04:55:02 +0000935 elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].appendChild(newItem);
rniwa@webkit.org40a1cb32009-08-20 00:14:19 +0000936 }
937}
938
commit-queue@webkit.org92964672013-07-31 04:55:02 +0000939function startNewMarkupGroup(label) {
940 if (!elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].hasChildNodes())
941 elementsForDumpingMarkupList.pop();
942 elementsForDumpingMarkupList.push(document.createElement('br'));
943 elementsForDumpingMarkupList.push(document.createTextNode(label));
944 elementsForDumpingMarkupList.push(document.createElement('ol'));
945}
946
kocienda495c3032004-04-06 15:21:34 +0000947//-------------------------------------------------------------------------------------------------------
vickia1720332004-07-06 16:23:43 +0000948
kdeckerfd91e242004-07-14 00:38:38 +0000949
vickia1720332004-07-06 16:23:43 +0000950function execBackColorCommand() {
951 document.execCommand("BackColor", false, "Chartreuse");
rniwa@webkit.org307648702009-08-20 23:37:53 +0000952 debugForDumpAsText('execBackColorCommand');
vickia1720332004-07-06 16:23:43 +0000953}
954function backColorCommand() {
955 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000956 queueCommand(execBackColorCommand, commandCount * commandDelay);
vickia1720332004-07-06 16:23:43 +0000957 commandCount++;
958 }
959 else {
960 execBackColorCommand();
961 }
962}
963
rniwa@webkit.org307648702009-08-20 23:37:53 +0000964
965function execForeColorCommand(color) {
966 document.execCommand("ForeColor", false, color);
967 debugForDumpAsText('execForeColorCommand');
968}
969function foreColorCommand(color) {
970 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000971 queueCommand(execForeColorCommand.bind(execForeColorCommand, color), commandCount * commandDelay);
rniwa@webkit.org307648702009-08-20 23:37:53 +0000972 commandCount++;
973 } else
974 execForeColorCommand(color);
975}
976
vickia1720332004-07-06 16:23:43 +0000977//-------------------------------------------------------------------------------------------------------
978
kdeckerfd91e242004-07-14 00:38:38 +0000979
980function runCommand(command, arg1, arg2) {
981 document.execCommand(command,arg1,arg2);
vickia1720332004-07-06 16:23:43 +0000982}
kdeckerfd91e242004-07-14 00:38:38 +0000983
984function executeCommand(command,arg1,arg2) {
vickia1720332004-07-06 16:23:43 +0000985 if (commandDelay > 0) {
rniwa@webkit.org54cb2002012-12-17 23:54:18 +0000986 queueCommand(runCommand, commandCount * commandDelay);
vickia1720332004-07-06 16:23:43 +0000987 commandCount++;
988 }
989 else {
kdeckerfd91e242004-07-14 00:38:38 +0000990 runCommand(command,arg1,arg2);
vickia1720332004-07-06 16:23:43 +0000991 }
kdeckerfd91e242004-07-14 00:38:38 +0000992}
993