selection.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <!DOCTYPE HTML>
  2. <!--
  3. Any copyright is dedicated to the Public Domain.
  4. http://creativecommons.org/licenses/publicdomain/
  5. Test: Selected text, background, decorations
  6. -->
  7. <html class="reftest-wait"><head>
  8. <title>text-overflow: Selected text, background, decorations</title>
  9. <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
  10. <style type="text/css">
  11. @font-face {
  12. font-family: DejaVuSansMono;
  13. src: url(../fonts/DejaVuSansMono.woff);
  14. }
  15. @font-face {
  16. font-family: TestEllipsisFallback;
  17. src: url(TestEllipsisFallback.woff);
  18. }
  19. html,body {
  20. color:black; background-color:white; font-size:16px; padding:0; margin:0; font-family:DejaVuSansMono;
  21. }
  22. .test {
  23. overflow:auto;
  24. text-overflow:ellipsis ellipsis;
  25. white-space:nowrap;
  26. width: 5em;
  27. position:relative;
  28. margin-top:1em;
  29. padding-left: 0.9em;
  30. padding-right: 1.3em;
  31. }
  32. .hidden {
  33. overflow:hidden;
  34. width: 4.4em;
  35. }
  36. .rlo {
  37. unicode-bidi: bidi-override; direction: rtl;
  38. }
  39. .lro {
  40. unicode-bidi: bidi-override; direction: ltr;
  41. }
  42. .rtl {
  43. direction:rtl;
  44. }
  45. x {font-family:DejaVuSansMono;}
  46. </style>
  47. <script>
  48. function getTextNode(elm) {
  49. if (elm.nodeType != 3)
  50. return getTextNode(elm.firstChild);
  51. return elm;
  52. }
  53. function addRange(elm) {
  54. try {
  55. var sel = window.getSelection();
  56. var range = document.createRange();
  57. var startNode = elm.getAttribute('startNode');
  58. if (startNode == null)
  59. startNode = getTextNode(elm);
  60. else
  61. startNode = getTextNode(elm.childNodes[startNode])
  62. var start = elm.getAttribute('start');
  63. if (start == null) start = 2;
  64. var endNode = elm.getAttribute('endNode');
  65. if (endNode == null)
  66. endNode = startNode;
  67. else
  68. endNode = getTextNode(elm.childNodes[endNode])
  69. var end = elm.getAttribute('end');
  70. if (end == null) end = endNode.textContent.length;
  71. if (startNode==endNode && start > end) return;
  72. if (startNode==null) return;
  73. range.setStart(startNode, start);
  74. range.setEnd(endNode, end);
  75. sel.addRange(range);
  76. } catch (e) {
  77. alert(e+'\n'+elm.id+'\n'+t)
  78. }
  79. }
  80. function selectText() {
  81. var divs = document.getElementsByTagName('div');
  82. for (i = 0; i < divs.length; ++i) {
  83. addRange(divs[i]);
  84. }
  85. document.body.offsetHeight;
  86. setTimeout(function(){document.documentElement.removeAttribute('class')},2000);
  87. }
  88. </script>
  89. </head><body onload="selectText();">
  90. <!-- LTR overflow:hidden -->
  91. <div contenteditable="true" spellcheck="true" class="test ltr hidden">Mispe|led word</div>
  92. <span style="display:block;width:15em"><div contenteditable="true" spellcheck="true" class="test ltr hidden" style="width:auto; float:right; font-family:TestEllipsisFallback; text-indent:-1em; " start=0 end=9><x>M ispeled word</x></div></span><br clear="all">
  93. <div contenteditable="true" spellcheck="true" class="test ltr hidden"><span class="rlo">Mispelled word</span></div>
  94. <div contenteditable="true" spellcheck="true" class="test ltr hidden"><span class="rlo">Mispelled</span><span class="rlo"> word</span></div>
  95. <div contenteditable="true" spellcheck="true" class="test ltr hidden"><span class="rlo">Mis</span><span class="rlo">pelled word</div>
  96. <div contenteditable="true" spellcheck="true" class="test ltr hidden" endNode="1" style="text-indent:-0.2em"><span>Mis</span><span>pe|led</span><span> word</span></div>
  97. <!-- RTL overflow:hidden -->
  98. <div contenteditable="true" spellcheck="true" class="test rtl hidden">Mispelled word</div>
  99. <div contenteditable="true" spellcheck="true" class="test rtl hidden" end="2"><span class="lro">Mispelled word</span></div>
  100. <div contenteditable="true" spellcheck="true" class="test rtl hidden"><span class="lro">Mispelled</span><span class="rlo"> word</span></div>
  101. <div contenteditable="true" spellcheck="true" class="test rtl hidden"><span class="rlo">Mis</span><span class="rlo">pelled word</div>
  102. <div contenteditable="true" spellcheck="true" class="test rtl hidden"><span class="rlo">Mis</span><span class="rlo">pelled word</div>
  103. <div contenteditable="true" spellcheck="true" class="test rtl hidden"><span class="rlo" style="margin-right:-0.2em">Mis</span><span class="rlo">pelled</span><span class="rlo"> word</span></div>
  104. </body></html>