Bug 640321 - Register the mouse event handlers for the editor in the system group; r=roc

This commit is contained in:
Ehsan Akhgari 2011-03-16 15:34:30 -04:00
parent 4f4adbc733
commit e4ad8f774b
5 changed files with 214 additions and 4 deletions

View File

@ -165,8 +165,9 @@ nsEditorEventListener::InstallToEditor()
NS_EVENT_FLAG_BUBBLE, sysGroup);
NS_ENSURE_SUCCESS(rv, rv);
rv = piTarget->AddEventListenerByIID(static_cast<nsIDOMMouseListener*>(this),
NS_GET_IID(nsIDOMMouseListener));
rv = elmP->AddEventListenerByIID(static_cast<nsIDOMMouseListener*>(this),
NS_GET_IID(nsIDOMMouseListener),
NS_EVENT_FLAG_CAPTURE);
NS_ENSURE_SUCCESS(rv, rv);
// Focus event doesn't bubble so adding the listener to capturing phase.
@ -236,8 +237,9 @@ nsEditorEventListener::UninstallFromEditor()
NS_LITERAL_STRING("drop"),
NS_EVENT_FLAG_BUBBLE, sysGroup);
piTarget->RemoveEventListenerByIID(static_cast<nsIDOMMouseListener*>(this),
NS_GET_IID(nsIDOMMouseListener));
elmP->RemoveEventListenerByIID(static_cast<nsIDOMMouseListener*>(this),
NS_GET_IID(nsIDOMMouseListener),
NS_EVENT_FLAG_CAPTURE);
elmP->RemoveEventListenerByIID(static_cast<nsIDOMFocusListener*>(this),
NS_GET_IID(nsIDOMFocusListener),

View File

@ -72,6 +72,7 @@ _TEST_FILES = \
test_bug620906.html \
test_bug622371.html \
test_bug629845.html \
test_bug640321.html \
test_CF_HTML_clipboard.html \
test_contenteditable_focus.html \
test_contenteditable_text_input_handling.html \

View File

@ -0,0 +1,193 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=640321
-->
<head>
<title>Test for Bug 640321</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/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=640321">Mozilla Bug 640321</a>
<p id="display"></p>
<div id="content" contenteditable style="text-align: center">
<img src="green.png">
</div>
<div id="clickaway" style="width: 10px; height: 10px"></div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 640321 **/
SimpleTest.waitForExplicitFinish();
SimpleTest.waitForFocus(function() {
var img = document.querySelector("img");
function cancel(e) { e.stopPropagation(); }
var content = document.getElementById("content");
content.addEventListener("mousedown", cancel, false);
content.addEventListener("mousemove", cancel, false);
content.addEventListener("mouseup", cancel, false);
/**
* This function is a generic resizer test.
* We have 8 resizers that we'd like to test, and each can be moved in 8 different directions.
* In specifying baseX, W can be considered to be the width of the image, and for baseY, H
* can be considered to be the height of the image. deltaX and deltaY are regular pixel values
* which can be positive or negative.
*/
const W = 1;
const H = 1;
function testResizer(baseX, baseY, deltaX, deltaY, expectedDeltaX, expectedDeltaY) {
ok(true, "testResizer(" + [baseX, baseY, deltaX, deltaY, expectedDeltaX, expectedDeltaY].join(", ") + ")");
// Reset the dimensions of the image
img.style.width = "100px";
img.style.height = "100px";
var rect = img.getBoundingClientRect();
is(rect.width, 100, "Sanity check the length");
is(rect.height, 100, "Sanity check the height");
// Click on the image to show the resizers
synthesizeMouseAtCenter(img, {});
// Determine which resizer we're dealing with
var basePosX = rect.width * baseX;
var basePosY = rect.height * baseY;
// Click on the correct resizer
synthesizeMouse(img, basePosX, basePosY, {type: "mousedown"});
// Drag it delta pixels to the right and bottom (or maybe left and top!)
synthesizeMouse(img, basePosX + deltaX, basePosY + deltaY, {type: "mousemove"});
// Release the mouse button
synthesizeMouse(img, basePosX + deltaX, basePosY + deltaY, {type: "mouseup"});
// Move the mouse delta more pixels to the same direction to make sure that the
// resize operation has stopped.
synthesizeMouse(img, basePosX + deltaX * 2, basePosY + deltaY * 2, {type: "mousemove"});
// Click outside of the image to hide the resizers
synthesizeMouseAtCenter(document.getElementById("clickaway"), {});
// Get the new dimensions for the image
var newRect = img.getBoundingClientRect();
is(newRect.width, rect.width + expectedDeltaX, "The width should be increased by " + expectedDeltaX + " pixels");
is(newRect.height, rect.height + expectedDeltaY, "The height should be increased by " + expectedDeltaY + "pixels");
}
function runTests(preserveRatio) {
// Account for changes in the resizing behavior when we're trying to preserve
// the aspect ration.
// ignoredGrowth means we don't change the size of a dimension because otherwise
// the aspect ratio would change undesirably.
// needlessGrowth means that we change the size of a dimension perpendecular to
// the mouse movement axis in order to preserve the aspect ratio.
// reversedGrowth means that we change the size of a dimension in the opposite
// direction to the mouse movement in order to maintain the aspect ratio.
const ignoredGrowth = preserveRatio ? 0 : 1;
const needlessGrowth = preserveRatio ? 1 : 0;
const reversedGrowth = preserveRatio ? -1 : 1;
SpecialPowers.setBoolPref("editor.resizing.preserve_ratio", preserveRatio);
// top resizer
testResizer(W/2, 0, -10, -10, 0, 10);
testResizer(W/2, 0, -10, 0, 0, 0);
testResizer(W/2, 0, -10, 10, 0, -10);
testResizer(W/2, 0, 0, -10, 0, 10);
testResizer(W/2, 0, 0, 0, 0, 0);
testResizer(W/2, 0, 0, 10, 0, -10);
testResizer(W/2, 0, 10, -10, 0, 10);
testResizer(W/2, 0, 10, 0, 0, 0);
testResizer(W/2, 0, 10, 10, 0, -10);
// top right resizer
testResizer( W, 0, -10, -10, -10 * reversedGrowth, 10);
testResizer( W, 0, -10, 0, -10 * ignoredGrowth, 0);
testResizer( W, 0, -10, 10, -10, -10);
testResizer( W, 0, 0, -10, 10 * needlessGrowth, 10);
testResizer( W, 0, 0, 0, 0, 0);
testResizer( W, 0, 0, 10, 0, -10 * ignoredGrowth);
testResizer( W, 0, 10, -10, 10, 10);
testResizer( W, 0, 10, 0, 10, 10 * needlessGrowth);
testResizer( W, 0, 10, 10, 10, -10 * reversedGrowth);
// right resizer
testResizer( W, H/2, -10, -10, -10, 0);
testResizer( W, H/2, -10, 0, -10, 0);
testResizer( W, H/2, -10, 10, -10, 0);
testResizer( W, H/2, 0, -10, 0, 0);
testResizer( W, H/2, 0, 0, 0, 0);
testResizer( W, H/2, 0, 10, 0, 0);
testResizer( W, H/2, 10, -10, 10, 0);
testResizer( W, H/2, 10, 0, 10, 0);
testResizer( W, H/2, 10, 10, 10, 0);
// bottom right resizer
testResizer( W, H, -10, -10, -10, -10);
testResizer( W, H, -10, 0, -10 * ignoredGrowth, 0);
testResizer( W, H, -10, 10, -10 * reversedGrowth, 10);
testResizer( W, H, 0, -10, 0, -10 * ignoredGrowth);
testResizer( W, H, 0, 0, 0, 0);
testResizer( W, H, 0, 10, 10 * needlessGrowth, 10);
testResizer( W, H, 10, -10, 10, -10 * reversedGrowth);
testResizer( W, H, 10, 0, 10, 10 * needlessGrowth);
testResizer( W, H, 10, 10, 10, 10);
// bottom resizer
testResizer(W/2, H, -10, -10, 0, -10);
testResizer(W/2, H, -10, 0, 0, 0);
testResizer(W/2, H, -10, 10, 0, 10);
testResizer(W/2, H, 0, -10, 0, -10);
testResizer(W/2, H, 0, 0, 0, 0);
testResizer(W/2, H, 0, 10, 0, 10);
testResizer(W/2, H, 10, -10, 0, -10);
testResizer(W/2, H, 10, 0, 0, 0);
testResizer(W/2, H, 10, 10, 0, 10);
// bottom left resizer
testResizer( 0, H, -10, -10, 10, -10 * reversedGrowth);
testResizer( 0, H, -10, 0, 10, 10 * needlessGrowth);
testResizer( 0, H, -10, 10, 10, 10);
testResizer( 0, H, 0, -10, 0, -10 * ignoredGrowth);
testResizer( 0, H, 0, 0, 0, 0);
testResizer( 0, H, 0, 10, 10 * needlessGrowth, 10);
testResizer( 0, H, 10, -10, -10, -10);
testResizer( 0, H, 10, 0, -10 * ignoredGrowth, 0);
testResizer( 0, H, 10, 10, -10 * reversedGrowth, 10);
// left resizer
testResizer( 0, H/2, -10, -10, 10, 0);
testResizer( 0, H/2, -10, 0, 10, 0);
testResizer( 0, H/2, -10, 10, 10, 0);
testResizer( 0, H/2, 0, -10, 0, 0);
testResizer( 0, H/2, 0, 0, 0, 0);
testResizer( 0, H/2, 0, 10, 0, 0);
testResizer( 0, H/2, 10, -10, -10, 0);
testResizer( 0, H/2, 10, 0, -10, 0);
testResizer( 0, H/2, 10, 10, -10, 0);
// top left resizer
testResizer( 0, 0, -10, -10, 10, 10);
testResizer( 0, 0, -10, 0, 10, 10 * needlessGrowth);
testResizer( 0, 0, -10, 10, 10, -10 * reversedGrowth);
testResizer( 0, 0, 0, -10, 10 * needlessGrowth, 10);
testResizer( 0, 0, 0, 0, 0, 0);
testResizer( 0, 0, 0, 10, 0, -10 * ignoredGrowth);
testResizer( 0, 0, 10, -10, -10 * reversedGrowth, 10);
testResizer( 0, 0, 10, 0, -10 * ignoredGrowth, 0);
testResizer( 0, 0, 10, 10, -10, -10);
SpecialPowers.clearUserPref("editor.resizing.preserve_ratio");
}
runTests(false);
runTests(true);
SimpleTest.finish();
});
</script>
</pre>
</body>
</html>

View File

@ -124,6 +124,9 @@ SpecialPowersObserver.prototype = {
} else if (aMessage.json.op == "set") {
if (!prefName || !prefType || prefValue === null)
throw new SpecialPowersException("Invalid parameters for set in SPPrefService");
} else if (aMessage.json.op == "clear") {
if (!prefName)
throw new SpecialPowersException("Invalid parameters for clear in SPPrefService");
} else {
throw new SpecialPowersException("Invalid operation for SPPrefService");
}
@ -149,6 +152,11 @@ SpecialPowersObserver.prototype = {
return(prefs.getComplexValue(prefName, prefValue[0]));
else
return(prefs.setComplexValue(prefName, prefValue[0], prefValue[1]));
case "":
if (aMessage.json.op == "clear") {
prefs.clearUserPref(prefName);
return;
}
}
break;
default:

View File

@ -70,6 +70,12 @@ var SpecialPowers = {
return (this._setPref(aPrefName, 'COMPLEX', aValue, aIid));
},
// Mimic the clearUserPref API
clearUserPref: function(aPrefName) {
var msg = {'op':'clear', 'prefName': aPrefName, 'prefType': ""};
sendSyncMessage('SPPrefService', msg);
},
// Private pref functions to communicate to chrome
_getPref: function(aPrefName, aPrefType, aIid) {
var msg = {};