Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: LayoutTests/editing/editing.js

Issue 225303002: Let Selection.collapse remember a raw Position instead of a canonicalized one. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix setSelectedRange arguments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //------------------------------------------------------------------------------ ------------------------- 1 //------------------------------------------------------------------------------ -------------------------
2 // Java script library to run editing layout tests 2 // Java script library to run editing layout tests
3 3
4 var commandCount = 1; 4 var commandCount = 1;
5 var commandDelay = window.location.search.substring(1); 5 var commandDelay = window.location.search.substring(1);
6 if (commandDelay == '') 6 if (commandDelay == '')
7 commandDelay = 0; 7 commandDelay = 0;
8 var selection = window.getSelection(); 8 var selection = window.getSelection();
9 9
10 //------------------------------------------------------------------------------ ------------------------- 10 //------------------------------------------------------------------------------ -------------------------
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 i++; 886 i++;
887 if (i < queue.length) 887 if (i < queue.length)
888 setTimeout(runCommand, commandDelay); 888 setTimeout(runCommand, commandDelay);
889 else if (window.testRunner) 889 else if (window.testRunner)
890 testRunner.notifyDone(); 890 testRunner.notifyDone();
891 } 891 }
892 892
893 window.queueCommand = queueCommand; 893 window.queueCommand = queueCommand;
894 })(); 894 })();
895 895
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;
904
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 }
915
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[offs et] == '\n')
920 offset++;
921 return { 'node': node, 'offset': offset };
922 }
923
924 if (node.nodeName == 'BR' || node.nodeName == 'IMG')
925 return { 'node': node.parentNode, 'offset': offset };
926
927 return null;
928 });
929
930 if (firstVisiblePosition)
931 selection.collapse(firstVisiblePosition.node, firstVisiblePosition.o ffset);
932 else
933 selection.collapse(elem, 0);
934 } else {
935 selection.removeAllRanges();
936 }
937 }
938
896 function runEditingTest() { 939 function runEditingTest() {
897 if (window.testRunner) 940 if (window.testRunner)
898 testRunner.dumpEditingCallbacks(); 941 testRunner.dumpEditingCallbacks();
899 942
900 var elem = document.getElementById("test"); 943 focusOnFirstTextInTestElementIfExists();
901 var selection = window.getSelection(); 944
902 if (elem)
903 selection.collapse(elem, 0);
904 else
905 selection.removeAllRanges();
906 editingTest(); 945 editingTest();
907 } 946 }
908 947
909 var dumpAsText = false; 948 var dumpAsText = false;
910 var elementsForDumpingMarkupList = [document.createElement('ol')]; 949 var elementsForDumpingMarkupList = [document.createElement('ol')];
911 950
912 function runDumpAsTextEditingTest(enableCallbacks) { 951 function runDumpAsTextEditingTest(enableCallbacks) {
913 if (window.testRunner) { 952 if (window.testRunner) {
914 testRunner.dumpAsText(); 953 testRunner.dumpAsText();
915 if (enableCallbacks) 954 if (enableCallbacks)
916 testRunner.dumpEditingCallbacks(); 955 testRunner.dumpEditingCallbacks();
917 } 956 }
918 957
919 dumpAsText = true; 958 dumpAsText = true;
920 959
921 var elem = document.getElementById("test"); 960 focusOnFirstTextInTestElementIfExists();
922 var selection = window.getSelection(); 961
923 if (elem)
924 selection.collapse(elem, 0);
925 else
926 selection.removeAllRanges();
927 editingTest(); 962 editingTest();
928 963
929 for (var i = 0; i < elementsForDumpingMarkupList.length; i++) 964 for (var i = 0; i < elementsForDumpingMarkupList.length; i++)
930 document.body.appendChild(elementsForDumpingMarkupList[i]); 965 document.body.appendChild(elementsForDumpingMarkupList[i]);
931 } 966 }
932 967
933 function debugForDumpAsText(name) { 968 function debugForDumpAsText(name) {
934 if (dumpAsText && document.getElementById("root")) { 969 if (dumpAsText && document.getElementById("root")) {
935 var newItem = document.createElement('li'); 970 var newItem = document.createElement('li');
936 newItem.appendChild(document.createTextNode(name+": "+document.getElemen tById("root").innerHTML)); 971 newItem.appendChild(document.createTextNode(name+": "+document.getElemen tById("root").innerHTML));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 function executeCommand(command,arg1,arg2) { 1021 function executeCommand(command,arg1,arg2) {
987 if (commandDelay > 0) { 1022 if (commandDelay > 0) {
988 queueCommand(runCommand, commandCount * commandDelay); 1023 queueCommand(runCommand, commandCount * commandDelay);
989 commandCount++; 1024 commandCount++;
990 } 1025 }
991 else { 1026 else {
992 runCommand(command,arg1,arg2); 1027 runCommand(command,arg1,arg2);
993 } 1028 }
994 } 1029 }
995 1030
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698