Opera 12.15 Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

documentedit.selections.ot 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* -*- Mode: c++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
  2. group "DocumentEdit.Selections";
  3. require init;
  4. require DOCUMENT_EDIT_SUPPORT;
  5. language ecmascript;
  6. html
  7. {
  8. "<html><head><title>empty range within an element containing only an image</title></head>\n"
  9. "<body>\n"
  10. " <div contentEditable>\n"
  11. " <div id='x'><img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAAI0lEQVR4nGNkYNjCgARYGBgY/v/3hnAYGbcyMaACdD4jmn4A7CkEc/PaWSMAAAAASUVORK5CYII='></div>\n"
  12. " </div>\n"
  13. "</body></html>"
  14. }
  15. test("Converting documentedit caret to selection range")
  16. {
  17. var x = document.getElementById('x');
  18. verify(x);
  19. var r = document.createRange();
  20. verify(r);
  21. r.setStart(x, 1);
  22. r.setEnd(x, 1);
  23. getSelection().removeAllRanges();
  24. getSelection().addRange(r);
  25. var r2 = getSelection().getRangeAt(0);
  26. verify(r2);
  27. // The range must be collapsed.
  28. verify(r2.startOffset == r2.endOffset);
  29. verify(r2.startContainer == r2.endContainer);
  30. verify(r2.collapsed);
  31. verify(r2.startContainer == x);
  32. verify(r2.startOffset == 1);
  33. }
  34. html
  35. {
  36. //! <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
  37. //! <html><head><title> selection and range properties when cursor is just after a BR tag </title></head>
  38. //! <body>
  39. //! <p style="white-space:pre">FAILED (This TC requires JavaScript enabled)</p>
  40. //! <iframe src=""></iframe>
  41. //! </body></html>
  42. }
  43. test("Selections when the caret is just after a br")
  44. language ecmascript;
  45. {
  46. var log=document.getElementsByTagName('p')[0].firstChild, passed=true, msg;
  47. var idoc = document.getElementsByTagName('iframe')[0].contentDocument;
  48. idoc.designMode = 'on';
  49. idoc.body.innerHTML = '<p><br></p>';
  50. idoc.defaultView.focus();
  51. var rng = idoc.createRange();
  52. rng.setStartAfter( idoc.getElementsByTagName('br')[0] );
  53. rng.setEndAfter( idoc.getElementsByTagName('br')[0] );
  54. idoc.defaultView.getSelection().removeAllRanges( );
  55. idoc.defaultView.getSelection().addRange( rng );
  56. /*
  57. We should now have something like <p><br>^</p> AFAIK. Time to test these:
  58. sel.focusNode
  59. sel.anchorNode
  60. rng.startContainer
  61. rng.endContainer
  62. */
  63. var theP = idoc.getElementsByTagName('p')[0];
  64. var iwindow = idoc.defaultView;
  65. var isel = iwindow.getSelection();
  66. verify(isel.anchorNode == theP);
  67. verify(isel.focusNode == theP);
  68. rng = isel.getRangeAt(0);
  69. verify(rng.startContainer == theP);
  70. verify(rng.endContainer == theP);
  71. }