зеркало из https://github.com/mozilla/gecko-dev.git
Bug 423523: Caret can leave div w/ contenteditable = true with repeated arrow keys, patch by Chris Pearce <chris@pearce.org.nz>, r+sr=peterv, a=beltzner
This commit is contained in:
Родитель
f11d5e8c9f
Коммит
908c443de8
|
@ -91,6 +91,7 @@ _TEST_FILES = \
|
|||
test_bug404209.xhtml \
|
||||
test_bug416896.html \
|
||||
test_bug420499.xul \
|
||||
test_bug423523.html \
|
||||
$(NULL)
|
||||
# test_bug396024.html is currently disabled because it interacts badly with
|
||||
# the "You can't print-preview while the page is loading" dialog.
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=423523
|
||||
-->
|
||||
<head>
|
||||
<title>Test for Bug 423523</title>
|
||||
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
|
||||
</head>
|
||||
<body onload="setTimeout(runtests, 200)">
|
||||
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=423523">Mozilla Bug 423523</a>
|
||||
<p id="display"></p>
|
||||
|
||||
<table>
|
||||
<tbody><tr>
|
||||
<td class="tdABB" id="tdTo">
|
||||
<p id="par1">Some text...</p></td>
|
||||
<td>
|
||||
<div id="div1" style="border: 1px solid silver; width: 250px;" contenteditable="true">This is some editable text.</div>
|
||||
</td></tr>
|
||||
</tbody></table>
|
||||
|
||||
|
||||
<div id="content" style="display: none">
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
/** Test for Bug 423523 **/
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
|
||||
function divIsFocused() {
|
||||
// Check if div is directly focused.
|
||||
var divNode = document.getElementById("div1");
|
||||
if (window.getSelection().focusNode == divNode) {
|
||||
return true;
|
||||
}
|
||||
// Check if one of the div's children has focus.
|
||||
var node = window.getSelection().focusNode;
|
||||
var childNodes = divNode.childNodes;
|
||||
for (var i=0; i<childNodes.length; i++) {
|
||||
if (childNodes[i] == node) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// Not focused (at least not the first gen kids, and
|
||||
// that's ok for this test).
|
||||
return false;
|
||||
}
|
||||
|
||||
function selectionOffsetIs(expectedOffset) {
|
||||
return window.getSelection().focusOffset == expectedOffset;
|
||||
}
|
||||
|
||||
function sendMouseClick() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
var rect=document.getElementById('div1').getBoundingClientRect();
|
||||
var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
|
||||
getInterface(Components.interfaces.nsIDOMWindowUtils);
|
||||
utils.sendMouseEvent('mousedown', rect.left+1, rect.top+1, 0, 1, 0);
|
||||
utils.sendMouseEvent('mouseup', rect.left+1, rect.top+1, 0, 1, 0);
|
||||
}
|
||||
|
||||
function runtests() {
|
||||
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
||||
sendMouseClick();
|
||||
window.getSelection().collapse(document.getElementById("div1").firstChild, 0);
|
||||
ok(divIsFocused(), "Div should be focused [0].");
|
||||
|
||||
ok(divIsFocused(), "Div should be focused [1].");
|
||||
ok(selectionOffsetIs(0), "Caret should be at offset 0");
|
||||
|
||||
synthesizeKey("VK_LEFT", { });
|
||||
ok(divIsFocused(), "Div should be focused [2].");
|
||||
ok(selectionOffsetIs(0), "Caret should be at offset 0");
|
||||
|
||||
synthesizeKey("VK_RIGHT", { });
|
||||
ok(divIsFocused(), "Div should be focused [3].");
|
||||
ok(selectionOffsetIs(1), "Caret should be at offset 1");
|
||||
|
||||
synthesizeKey("VK_LEFT", { });
|
||||
ok(divIsFocused(), "Div should be focused [4].");
|
||||
ok(selectionOffsetIs(0), "Caret should be at offset 0");
|
||||
|
||||
ok(divIsFocused(), "Div should be focused [5].");
|
||||
ok(selectionOffsetIs(0), "Caret should be at offset 0");
|
||||
sendMouseClick();
|
||||
|
||||
ok(divIsFocused(), "Div should be focused [6].");
|
||||
ok(selectionOffsetIs(0), "Caret should be at offset 0");
|
||||
synthesizeKey("VK_LEFT", { });
|
||||
|
||||
ok(divIsFocused(), "Div should be focused [7].");
|
||||
ok(selectionOffsetIs(0), "Caret should be at offset 0");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -2243,7 +2243,9 @@ nsFrameSelection::HandleClick(nsIContent *aNewFocus,
|
|||
|
||||
if (!aContinueSelection) {
|
||||
mMaintainRange = nsnull;
|
||||
mAncestorLimiter = nsnull;
|
||||
if (!IsValidSelectionPoint(this, aNewFocus)) {
|
||||
mAncestorLimiter = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
mHint = HINT(aHint);
|
||||
|
|
Загрузка…
Ссылка в новой задаче