Bug 417418 - do not treat context click as double click anymore in editor; r=ehsan

This commit is contained in:
arno renevier 2011-07-18 14:42:56 -04:00
parent 771b24b9fe
commit adc42180ca
3 changed files with 70 additions and 19 deletions

View File

@ -62,8 +62,6 @@
/*
* nsHTMLEditorEventListener implementation
*
* The only reason we need this is so a context mouse-click
* moves the caret or selects an element as it does for normal click
*/
#ifdef DEBUG
@ -134,17 +132,8 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMEvent* aMouseEvent)
nsresult res = mouseEvent->GetButton(&buttonNumber);
NS_ENSURE_SUCCESS(res, res);
PRBool isContextClick;
PRBool isContextClick = buttonNumber == 2;
#if defined(XP_MACOSX)
// Ctrl+Click for context menu
res = mouseEvent->GetCtrlKey(&isContextClick);
NS_ENSURE_SUCCESS(res, res);
#else
// Right mouse button for Windows, UNIX
isContextClick = buttonNumber == 2;
#endif
PRInt32 clickCount;
res = mouseEvent->GetDetail(&clickCount);
NS_ENSURE_SUCCESS(res, res);
@ -245,14 +234,8 @@ nsHTMLEditorEventListener::MouseDown(nsIDOMEvent* aMouseEvent)
}
}
// XXX: should we call nsHTMLEditUtils::IsTableElement here?
// that also checks for thead, tbody, tfoot
if (nsTextEditUtils::IsBody(node) ||
nsHTMLEditUtils::IsTableCellOrCaption(node) ||
nsHTMLEditUtils::IsTableRow(node) ||
nsHTMLEditUtils::IsTable(node))
if (isContextClick && !nsHTMLEditUtils::IsImage(node))
{
// This will place caret just inside table cell or at start of body
selection->Collapse(parent, offset);
}
else

View File

@ -52,6 +52,7 @@ _TEST_FILES = \
test_bug372345.html \
test_bug410986.html \
test_bug414526.html \
test_bug417418.html \
test_bug432225.html \
test_bug439808.html \
test_bug455992.html \

View File

@ -0,0 +1,67 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=417418
-->
<head>
<title>Test for Bug 417418</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=417418">Mozilla Bug 417418</a>
<div id="display" contenteditable="true">
<p id="coin">first paragraph</p>
<p>second paragraph. <img id="img" src="green.png"></p>
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
/** Test for Bug 417418 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(runTest);
function runTest() {
var rightClick = {type: 'mousedown', button: 2},
singleClick = {type: 'mousedown', button: 0};
var selection = window.getSelection();
var div = document.getElementById('display');
var img = document.getElementById('img');
var divRect = div.getBoundingClientRect();
var imgselected;
synthesizeMouse(div, divRect.width - 1, divRect.height - 1, rightClick);
ok(selection.isCollapsed, "selection is not collapsed");
selection.removeAllRanges();
synthesizeMouse(div, divRect.width - 1, divRect.height - 1, singleClick);
ok(selection.isCollapsed, "selection is not collapsed");
selection.removeAllRanges();
synthesizeMouseAtCenter(img, rightClick);
imgselected = selection.anchorNode.isSameNode(img.parentNode) &&
selection.anchorOffset === 1 &&
selection.rangeCount === 1;
ok(imgselected, "image is not selected");
selection.removeAllRanges();
synthesizeMouseAtCenter(img, singleClick);
imgselected = selection.anchorNode.isSameNode(img.parentNode) &&
selection.anchorOffset === 1 &&
selection.rangeCount === 1;
ok(imgselected, "image is not selected");
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>