Bug 910156 Add AssignKeyEventData() and AssignMouseEventData() for sharing the code in nsDOMEvent::DuplicatePrivateData() and nsDelayed*Event r=smaug

This commit is contained in:
Masayuki Nakano 2013-08-30 11:10:32 +09:00
parent f706ff755c
commit 1788d13287
5 changed files with 389 additions and 92 deletions

View File

@ -500,43 +500,47 @@ nsDOMEvent::DuplicatePrivateData()
nsEvent* newEvent = nullptr;
uint32_t msg = mEvent->message;
bool isInputEvent = false;
switch (mEvent->eventStructType) {
case NS_EVENT:
{
newEvent = new nsEvent(false, msg);
newEvent->AssignEventData(*mEvent, true);
break;
}
case NS_GUI_EVENT:
{
nsGUIEvent* oldGUIEvent = static_cast<nsGUIEvent*>(mEvent);
// Not copying widget, it is a weak reference.
newEvent = new nsGUIEvent(false, msg, nullptr);
nsGUIEvent* guiEvent = new nsGUIEvent(false, msg, nullptr);
guiEvent->AssignGUIEventData(*oldGUIEvent, true);
newEvent = guiEvent;
break;
}
case NS_SCROLLBAR_EVENT:
{
newEvent = new nsScrollbarEvent(false, msg, nullptr);
static_cast<nsScrollbarEvent*>(newEvent)->position =
static_cast<nsScrollbarEvent*>(mEvent)->position;
nsScrollbarEvent* oldScrollbarEvent =
static_cast<nsScrollbarEvent*>(mEvent);
nsScrollbarEvent* scrollbarEvent =
new nsScrollbarEvent(false, msg, nullptr);
scrollbarEvent->AssignGUIEventData(*scrollbarEvent, true);
scrollbarEvent->position = oldScrollbarEvent->position;
newEvent = scrollbarEvent;
break;
}
case NS_INPUT_EVENT:
{
newEvent = new nsInputEvent(false, msg, nullptr);
isInputEvent = true;
nsInputEvent* oldInputEvent = static_cast<nsInputEvent*>(mEvent);
nsInputEvent* inputEvent = new nsInputEvent(false, msg, nullptr);
inputEvent->AssignInputEventData(*oldInputEvent, true);
newEvent = inputEvent;
break;
}
case NS_KEY_EVENT:
{
nsKeyEvent* keyEvent = new nsKeyEvent(false, msg, nullptr);
nsKeyEvent* oldKeyEvent = static_cast<nsKeyEvent*>(mEvent);
isInputEvent = true;
keyEvent->keyCode = oldKeyEvent->keyCode;
keyEvent->charCode = oldKeyEvent->charCode;
keyEvent->location = oldKeyEvent->location;
keyEvent->isChar = oldKeyEvent->isChar;
keyEvent->mKeyNameIndex = oldKeyEvent->mKeyNameIndex;
nsKeyEvent* keyEvent = new nsKeyEvent(false, msg, nullptr);
keyEvent->AssignKeyEventData(*oldKeyEvent, true);
newEvent = keyEvent;
break;
}
@ -545,15 +549,7 @@ nsDOMEvent::DuplicatePrivateData()
nsMouseEvent* oldMouseEvent = static_cast<nsMouseEvent*>(mEvent);
nsMouseEvent* mouseEvent =
new nsMouseEvent(false, msg, nullptr, oldMouseEvent->reason);
isInputEvent = true;
mouseEvent->clickCount = oldMouseEvent->clickCount;
mouseEvent->acceptActivation = oldMouseEvent->acceptActivation;
mouseEvent->context = oldMouseEvent->context;
mouseEvent->relatedTarget = oldMouseEvent->relatedTarget;
mouseEvent->button = oldMouseEvent->button;
mouseEvent->buttons = oldMouseEvent->buttons;
mouseEvent->pressure = oldMouseEvent->pressure;
mouseEvent->inputSource = oldMouseEvent->inputSource;
mouseEvent->AssignMouseEventData(*oldMouseEvent, true);
newEvent = mouseEvent;
break;
}
@ -562,7 +558,7 @@ nsDOMEvent::DuplicatePrivateData()
nsDragEvent* oldDragEvent = static_cast<nsDragEvent*>(mEvent);
nsDragEvent* dragEvent =
new nsDragEvent(false, msg, nullptr);
isInputEvent = true;
dragEvent->AssignInputEventData(*oldDragEvent, true);
dragEvent->dataTransfer = oldDragEvent->dataTransfer;
dragEvent->clickCount = oldDragEvent->clickCount;
dragEvent->acceptActivation = oldDragEvent->acceptActivation;
@ -578,21 +574,27 @@ nsDOMEvent::DuplicatePrivateData()
{
nsClipboardEvent* oldClipboardEvent = static_cast<nsClipboardEvent*>(mEvent);
nsClipboardEvent* clipboardEvent = new nsClipboardEvent(false, msg);
clipboardEvent->AssignEventData(*oldClipboardEvent, true);
clipboardEvent->clipboardData = oldClipboardEvent->clipboardData;
newEvent = clipboardEvent;
break;
}
case NS_SCRIPT_ERROR_EVENT:
{
newEvent = new nsScriptErrorEvent(false, msg);
static_cast<nsScriptErrorEvent*>(newEvent)->lineNr =
static_cast<nsScriptErrorEvent*>(mEvent)->lineNr;
nsScriptErrorEvent* oldScriptErrorEvent =
static_cast<nsScriptErrorEvent*>(mEvent);
nsScriptErrorEvent* scriptErrorEvent = new nsScriptErrorEvent(false, msg);
scriptErrorEvent->AssignEventData(*oldScriptErrorEvent, true);
scriptErrorEvent->lineNr = oldScriptErrorEvent->lineNr;
newEvent = scriptErrorEvent;
break;
}
case NS_TEXT_EVENT:
{
newEvent = new nsTextEvent(false, msg, nullptr);
isInputEvent = true;
nsTextEvent* oldTextEvent = static_cast<nsTextEvent*>(mEvent);
nsTextEvent* textEvent = new nsTextEvent(false, msg, nullptr);
textEvent->AssignGUIEventData(*oldTextEvent, true);
newEvent = textEvent;
break;
}
case NS_COMPOSITION_EVENT:
@ -601,17 +603,18 @@ nsDOMEvent::DuplicatePrivateData()
new nsCompositionEvent(false, msg, nullptr);
nsCompositionEvent* oldCompositionEvent =
static_cast<nsCompositionEvent*>(mEvent);
compositionEvent->AssignGUIEventData(*oldCompositionEvent, true);
compositionEvent->data = oldCompositionEvent->data;
newEvent = compositionEvent;
break;
}
case NS_MOUSE_SCROLL_EVENT:
{
nsMouseScrollEvent* mouseScrollEvent =
new nsMouseScrollEvent(false, msg, nullptr);
isInputEvent = true;
nsMouseScrollEvent* oldMouseScrollEvent =
static_cast<nsMouseScrollEvent*>(mEvent);
nsMouseScrollEvent* mouseScrollEvent =
new nsMouseScrollEvent(false, msg, nullptr);
mouseScrollEvent->AssignInputEventData(*oldMouseScrollEvent, true);
mouseScrollEvent->isHorizontal = oldMouseScrollEvent->isHorizontal;
mouseScrollEvent->delta = oldMouseScrollEvent->delta;
mouseScrollEvent->relatedTarget = oldMouseScrollEvent->relatedTarget;
@ -624,11 +627,11 @@ nsDOMEvent::DuplicatePrivateData()
}
case NS_WHEEL_EVENT:
{
widget::WheelEvent* wheelEvent =
new widget::WheelEvent(false, msg, nullptr);
isInputEvent = true;
widget::WheelEvent* oldWheelEvent =
static_cast<widget::WheelEvent*>(mEvent);
widget::WheelEvent* wheelEvent =
new widget::WheelEvent(false, msg, nullptr);
wheelEvent->AssignInputEventData(*oldWheelEvent, true);
wheelEvent->deltaX = oldWheelEvent->deltaX;
wheelEvent->deltaY = oldWheelEvent->deltaY;
wheelEvent->deltaZ = oldWheelEvent->deltaZ;
@ -651,18 +654,24 @@ nsDOMEvent::DuplicatePrivateData()
}
case NS_SCROLLPORT_EVENT:
{
newEvent = new nsScrollPortEvent(false, msg, nullptr);
static_cast<nsScrollPortEvent*>(newEvent)->orient =
static_cast<nsScrollPortEvent*>(mEvent)->orient;
nsScrollPortEvent* oldScrollPortEvent =
static_cast<nsScrollPortEvent*>(mEvent);
nsScrollPortEvent* scrollPortEvent =
new nsScrollPortEvent(false, msg, nullptr);
scrollPortEvent->AssignGUIEventData(*oldScrollPortEvent, true);
scrollPortEvent->orient = oldScrollPortEvent->orient;
newEvent = scrollPortEvent;
break;
}
case NS_SCROLLAREA_EVENT:
{
nsScrollAreaEvent *newScrollAreaEvent =
nsScrollAreaEvent* oldScrollAreaEvent =
static_cast<nsScrollAreaEvent*>(mEvent);
nsScrollAreaEvent* scrollAreaEvent =
new nsScrollAreaEvent(false, msg, nullptr);
newScrollAreaEvent->mArea =
static_cast<nsScrollAreaEvent *>(mEvent)->mArea;
newEvent = newScrollAreaEvent;
scrollAreaEvent->AssignGUIEventData(*oldScrollAreaEvent, true);
scrollAreaEvent->mArea = oldScrollAreaEvent->mArea;
newEvent = scrollAreaEvent;
break;
}
case NS_MUTATION_EVENT:
@ -670,6 +679,7 @@ nsDOMEvent::DuplicatePrivateData()
nsMutationEvent* mutationEvent = new nsMutationEvent(false, msg);
nsMutationEvent* oldMutationEvent =
static_cast<nsMutationEvent*>(mEvent);
mutationEvent->AssignEventData(*oldMutationEvent, true);
mutationEvent->mRelatedNode = oldMutationEvent->mRelatedNode;
mutationEvent->mAttrName = oldMutationEvent->mAttrName;
mutationEvent->mPrevAttrValue = oldMutationEvent->mPrevAttrValue;
@ -680,13 +690,17 @@ nsDOMEvent::DuplicatePrivateData()
}
case NS_FORM_EVENT:
{
newEvent = new nsFormEvent(false, msg);
nsFormEvent* oldFormEvent = static_cast<nsFormEvent*>(mEvent);
nsFormEvent* formEvent = new nsFormEvent(false, msg);
formEvent->AssignEventData(*oldFormEvent, true);
newEvent = formEvent;
break;
}
case NS_FOCUS_EVENT:
{
nsFocusEvent* newFocusEvent = new nsFocusEvent(false, msg);
nsFocusEvent* oldFocusEvent = static_cast<nsFocusEvent*>(mEvent);
newFocusEvent->AssignGUIEventData(*oldFocusEvent, true);
newFocusEvent->fromRaise = oldFocusEvent->fromRaise;
newFocusEvent->isRefocus = oldFocusEvent->isRefocus;
newEvent = newFocusEvent;
@ -694,34 +708,47 @@ nsDOMEvent::DuplicatePrivateData()
}
case NS_COMMAND_EVENT:
{
newEvent = new nsCommandEvent(false, mEvent->userType,
static_cast<nsCommandEvent*>(mEvent)->command, nullptr);
nsCommandEvent* oldCommandEvent = static_cast<nsCommandEvent*>(mEvent);
nsCommandEvent* commandEvent =
new nsCommandEvent(false, mEvent->userType,
oldCommandEvent->command, nullptr);
commandEvent->AssignGUIEventData(*oldCommandEvent, true);
newEvent = commandEvent;
break;
}
case NS_UI_EVENT:
{
newEvent = new nsUIEvent(false, msg,
static_cast<nsUIEvent*>(mEvent)->detail);
nsUIEvent* oldUIEvent = static_cast<nsUIEvent*>(mEvent);
nsUIEvent* uiEvent = new nsUIEvent(false, msg, oldUIEvent->detail);
uiEvent->AssignEventData(*oldUIEvent, true);
newEvent = uiEvent;
break;
}
case NS_SVGZOOM_EVENT:
{
newEvent = new nsGUIEvent(false, msg, nullptr);
newEvent->eventStructType = NS_SVGZOOM_EVENT;
nsGUIEvent* oldGUIEvent = static_cast<nsGUIEvent*>(mEvent);
nsGUIEvent* guiEvent = new nsGUIEvent(false, msg, nullptr);
guiEvent->eventStructType = NS_SVGZOOM_EVENT;
guiEvent->AssignGUIEventData(*oldGUIEvent, true);
newEvent = guiEvent;
break;
}
case NS_SMIL_TIME_EVENT:
{
newEvent = new nsUIEvent(false, msg, 0);
newEvent->eventStructType = NS_SMIL_TIME_EVENT;
nsUIEvent* oldUIEvent = static_cast<nsUIEvent*>(mEvent);
nsUIEvent* uiEvent = new nsUIEvent(false, msg, 0);
uiEvent->eventStructType = NS_SMIL_TIME_EVENT;
uiEvent->AssignGUIEventData(*oldUIEvent, true);
newEvent = uiEvent;
break;
}
case NS_SIMPLE_GESTURE_EVENT:
{
nsSimpleGestureEvent* oldSimpleGestureEvent = static_cast<nsSimpleGestureEvent*>(mEvent);
nsSimpleGestureEvent* oldSimpleGestureEvent =
static_cast<nsSimpleGestureEvent*>(mEvent);
nsSimpleGestureEvent* simpleGestureEvent =
new nsSimpleGestureEvent(false, msg, nullptr, 0, 0.0);
isInputEvent = true;
simpleGestureEvent->AssignInputEventData(*oldSimpleGestureEvent, true);
simpleGestureEvent->direction = oldSimpleGestureEvent->direction;
simpleGestureEvent->delta = oldSimpleGestureEvent->delta;
simpleGestureEvent->clickCount = oldSimpleGestureEvent->clickCount;
@ -732,27 +759,34 @@ nsDOMEvent::DuplicatePrivateData()
{
nsTransitionEvent* oldTransitionEvent =
static_cast<nsTransitionEvent*>(mEvent);
newEvent = new nsTransitionEvent(false, msg,
oldTransitionEvent->propertyName,
oldTransitionEvent->elapsedTime,
oldTransitionEvent->pseudoElement);
nsTransitionEvent* transitionEvent =
new nsTransitionEvent(false, msg,
oldTransitionEvent->propertyName,
oldTransitionEvent->elapsedTime,
oldTransitionEvent->pseudoElement);
transitionEvent->AssignEventData(*oldTransitionEvent, true);
newEvent = transitionEvent;
break;
}
case NS_ANIMATION_EVENT:
{
nsAnimationEvent* oldAnimationEvent =
static_cast<nsAnimationEvent*>(mEvent);
newEvent = new nsAnimationEvent(false, msg,
oldAnimationEvent->animationName,
oldAnimationEvent->elapsedTime,
oldAnimationEvent->pseudoElement);
nsAnimationEvent* animationEvent =
new nsAnimationEvent(false, msg,
oldAnimationEvent->animationName,
oldAnimationEvent->elapsedTime,
oldAnimationEvent->pseudoElement);
animationEvent->AssignEventData(*oldAnimationEvent, true);
newEvent = animationEvent;
break;
}
case NS_TOUCH_EVENT:
{
nsTouchEvent *oldTouchEvent = static_cast<nsTouchEvent*>(mEvent);
newEvent = new nsTouchEvent(false, oldTouchEvent);
isInputEvent = true;
nsTouchEvent* oldTouchEvent = static_cast<nsTouchEvent*>(mEvent);
nsTouchEvent* touchEvent = new nsTouchEvent(false, oldTouchEvent);
touchEvent->AssignInputEventData(*oldTouchEvent, true);
newEvent = touchEvent;
break;
}
default:
@ -762,19 +796,7 @@ nsDOMEvent::DuplicatePrivateData()
}
}
if (isInputEvent) {
nsInputEvent* oldInputEvent = static_cast<nsInputEvent*>(mEvent);
nsInputEvent* newInputEvent = static_cast<nsInputEvent*>(newEvent);
newInputEvent->modifiers = oldInputEvent->modifiers;
}
newEvent->target = mEvent->target;
newEvent->currentTarget = mEvent->currentTarget;
newEvent->originalTarget = mEvent->originalTarget;
newEvent->mFlags = mEvent->mFlags;
newEvent->time = mEvent->time;
newEvent->refPoint = mEvent->refPoint;
newEvent->userType = mEvent->userType;
newEvent->mFlags = mEvent->mFlags;
mEvent = newEvent;
mPresContext = nullptr;

View File

@ -556,13 +556,6 @@ protected:
}
protected:
void Init(nsInputEvent* aEvent)
{
mEvent->time = aEvent->time;
mEvent->refPoint = aEvent->refPoint;
mEvent->modifiers = aEvent->modifiers;
}
nsDelayedInputEvent()
: nsDelayedEvent(), mEvent(nullptr) {}
@ -579,8 +572,7 @@ protected:
aEvent->widget,
aEvent->reason,
aEvent->context);
Init(aEvent);
static_cast<nsMouseEvent*>(mEvent)->clickCount = aEvent->clickCount;
static_cast<nsMouseEvent*>(mEvent)->AssignMouseEventData(*aEvent, false);
}
virtual ~nsDelayedMouseEvent()
@ -597,12 +589,7 @@ protected:
mEvent = new nsKeyEvent(aEvent->mFlags.mIsTrusted,
aEvent->message,
aEvent->widget);
Init(aEvent);
static_cast<nsKeyEvent*>(mEvent)->keyCode = aEvent->keyCode;
static_cast<nsKeyEvent*>(mEvent)->charCode = aEvent->charCode;
static_cast<nsKeyEvent*>(mEvent)->alternativeCharCodes =
aEvent->alternativeCharCodes;
static_cast<nsKeyEvent*>(mEvent)->isChar = aEvent->isChar;
static_cast<nsKeyEvent*>(mEvent)->AssignKeyEventData(*aEvent, false);
}
virtual ~nsDelayedKeyEvent()

View File

@ -692,6 +692,20 @@ public:
nsCOMPtr<mozilla::dom::EventTarget> target;
nsCOMPtr<mozilla::dom::EventTarget> currentTarget;
nsCOMPtr<mozilla::dom::EventTarget> originalTarget;
void AssignEventData(const nsEvent& aEvent, bool aCopyTargets)
{
// eventStructType, message should be initialized with the constructor.
refPoint = aEvent.refPoint;
// lastRefPoint doesn't need to be copied.
time = aEvent.time;
// mFlags should be copied manually if it's necessary.
userType = aEvent.userType;
// typeString should be copied manually if it's necessary.
target = aCopyTargets ? aEvent.target : nullptr;
currentTarget = aCopyTargets ? aEvent.currentTarget : nullptr;
originalTarget = aCopyTargets ? aEvent.originalTarget : nullptr;
}
};
/**
@ -725,6 +739,17 @@ public:
/// Event for NPAPI plugin
void* pluginEvent;
void AssignGUIEventData(const nsGUIEvent& aEvent, bool aCopyTargets)
{
AssignEventData(aEvent, aCopyTargets);
// widget should be initialized with the constructor.
// pluginEvent shouldn't be copied because it may be referred after its
// instance is destroyed.
pluginEvent = nullptr;
}
};
/**
@ -894,6 +919,13 @@ public:
}
mozilla::widget::Modifiers modifiers;
void AssignInputEventData(const nsInputEvent& aEvent, bool aCopyTargets)
{
AssignGUIEventData(aEvent, aCopyTargets);
modifiers = aEvent.modifiers;
}
};
/**
@ -929,6 +961,18 @@ public:
// Possible values at nsIDOMMouseEvent
uint16_t inputSource;
void AssignMouseEventBaseData(const nsMouseEvent_base& aEvent,
bool aCopyTargets)
{
AssignInputEventData(aEvent, aCopyTargets);
relatedTarget = aCopyTargets ? aEvent.relatedTarget : nullptr;
button = aEvent.button;
buttons = aEvent.buttons;
pressure = aEvent.pressure;
inputSource = aEvent.inputSource;
}
};
class nsMouseEvent : public nsMouseEvent_base
@ -1024,6 +1068,15 @@ public:
/// The number of mouse clicks
uint32_t clickCount;
void AssignMouseEventData(const nsMouseEvent& aEvent, bool aCopyTargets)
{
AssignMouseEventBaseData(aEvent, aCopyTargets);
acceptActivation = aEvent.acceptActivation;
ignoreRootScrollFrame = aEvent.ignoreRootScrollFrame;
clickCount = aEvent.clickCount;
}
};
/**
@ -1116,6 +1169,21 @@ public:
}
#undef NS_DEFINE_KEYNAME
}
void AssignKeyEventData(const nsKeyEvent& aEvent, bool aCopyTargets)
{
AssignInputEventData(aEvent, aCopyTargets);
keyCode = aEvent.keyCode;
charCode = aEvent.charCode;
location = aEvent.location;
alternativeCharCodes = aEvent.alternativeCharCodes;
isChar = aEvent.isChar;
mKeyNameIndex = aEvent.mKeyNameIndex;
// Don't copy mNativeKeyEvent because it may be referred after its instance
// is destroyed.
mNativeKeyEvent = nullptr;
}
};
/**

View File

@ -50,6 +50,7 @@ MOCHITEST_CHROME_FILES = test_bug343416.xul \
empty_window.xul \
test_sizemode_events.xul \
test_bug760802.xul \
test_assign_event_data.html \
$(NULL)
# test_bug413277.html mac-only based on 604789, 605178

View File

@ -0,0 +1,219 @@
<!DOCTYPE html>
<html>
<head>
<title>Testing ns*Event::Assign*EventData()</title>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
<script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/NativeKeyCodes.js"></script>
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
</head>
<body>
<div id="display">
<input id="input-text">
<button id="button">button</button>
</div>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
<script class="testbody" type="application/javascript">
SimpleTest.waitForExplicitFinish();
var gUtils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
const kIsMac = (navigator.platform.indexOf("Mac") == 0);
const kIsWin = (navigator.platform.indexOf("Win") == 0);
var gEvent = null;
var gCopiedEvent = [];
function onEvent(aEvent)
{
gEvent = aEvent;
for (var attr in aEvent) {
if (!attr.match(/^[A-Z0-9_]+$/) && // ignore const attributes
attr != "multipleActionsPrevented" && // multipleActionsPrevented isn't defined in any DOM event specs.
typeof(aEvent[attr]) != "function") {
gCopiedEvent.push({ name: attr, value: aEvent[attr]});
}
}
}
const WIN_KL_US = 0x409;
const MAC_KL_US = 0;
const NATIVE_SHIFT_LEFT = 0x0100;
const NATIVE_CONTROL_RIGHT = 0x0800;
const NATIVE_META_RIGHT = 0x8000;
const kTests = [
{ description: "nsKeyEvent (keydown of 'a' key without modifiers)",
targetID: "input-text", eventType: "keydown",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_A, 0, "a", "a");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_A, 0, "a", "a");
}
},
canRun: function () {
return (kIsMac || kIsWin);
},
todoMismatch: [ "key" ],
},
{ description: "nsKeyEvent (keyup of 'a' key without modifiers)",
targetID: "input-text", eventType: "keydown",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_A, 0, "a", "a");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_A, 0, "a", "a");
}
},
canRun: function () {
return (kIsMac || kIsWin);
},
todoMismatch: [ "key" ],
},
{ description: "nsKeyEvent (keypress of 'b' key with Shift)",
targetID: "input-text", eventType: "keypress",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_B, NATIVE_SHIFT_LEFT, "B", "B");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_B, NATIVE_SHIFT_LEFT, "B", "B");
}
},
canRun: function () {
return (kIsMac || kIsWin);
},
// "defaultPrevented" becomes true because the editor consumes the keypress event.
todoMismatch: [ "key", "defaultPrevented" ],
},
{ description: "nsKeyEvent (keypress of 'c' key with Accel)",
targetID: "input-text", eventType: "keypress",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
document.getElementById(this.targetID).focus();
if (kIsWin) {
gUtils.sendNativeKeyEvent(WIN_KL_US, WIN_VK_C, NATIVE_CONTROL_RIGHT, "\u0003", "c");
} else if (kIsMac) {
gUtils.sendNativeKeyEvent(MAC_KL_US, MAC_VK_ANSI_C, NATIVE_META_RIGHT, "c", "c");
}
},
canRun: function () {
return (kIsMac || kIsWin);
},
// "defaultPrevented" becomes true because the editor consumes the keypress event.
todoMismatch: [ "key", "defaultPrevented" ],
},
{ description: "nsMouseEvent (mousedown of left button without modifier)",
targetID: "button", eventType: "mousedown",
dispatchEvent: function () {
synthesizeMouseAtCenter(document.getElementById(this.targetID),
{ button: 0 });
},
canRun: function () {
return true;
},
todoMismatch: [],
},
{ description: "nsMouseEvent (click of middle button with Shift)",
// XXX I'm not sure why middle click event isn't fired on button element.
targetID: "input-text", eventType: "click",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
synthesizeMouseAtCenter(document.getElementById(this.targetID),
{ button: 1, shiftKey: true, pressure: 0.5 });
},
canRun: function () {
return true;
},
todoMismatch: [],
},
{ description: "nsMouseEvent (mouseup of right button with Alt)",
targetID: "button", eventType: "mouseup",
dispatchEvent: function () {
document.getElementById(this.targetID).value = "";
synthesizeMouseAtCenter(document.getElementById(this.targetID),
{ button: 2, altKey: true });
},
canRun: function () {
return true;
},
todoMismatch: [],
},
];
function doTest(aTest)
{
if (!aTest.canRun()) {
SimpleTest.executeSoon(runNextTest);
return;
}
gEvent = null;
gCopiedEvent = [];
var target = document.getElementById(aTest.targetID);
target.addEventListener(aTest.eventType, onEvent, true);
setTimeout(function () {
target.removeEventListener(aTest.eventType, onEvent, true);
ok(gEvent !== null, aTest.description + ": failed to get duplicated event");
ok(gCopiedEvent.length > 0, aTest.description + ": count of attribute of the event must be larger than 0");
for (var i = 0; i < gCopiedEvent.length; ++i) {
var name = gCopiedEvent[i].name;
if (name == "rangeOffset") {
todo(false, aTest.description + ": " + name + " attribute value is never reset (" + gEvent[name] + ")");
} else if (name == "eventPhase") {
is(gEvent[name], 0, aTest.description + ": mismatch with fixed value (" + name + ")");
} else if (name == "rangeParent" || name == "currentTarget") {
is(gEvent[name], null, aTest.description + ": mismatch with fixed value (" + name + ")");
} else if (aTest.todoMismatch.indexOf(name) >= 0) {
todo_is(gEvent[name], gCopiedEvent[i].value, aTest.description + ": mismatch (" + name + ")");
} else {
is(gEvent[name], gCopiedEvent[i].value, aTest.description + ": mismatch (" + name + ")");
}
}
runNextTest();
}, 0);
aTest.dispatchEvent();
}
var gIndex = -1;
function runNextTest()
{
if (++gIndex == kTests.length) {
finish();
return;
}
doTest(kTests[gIndex]);
}
function init()
{
SpecialPowers.setBoolPref("middlemouse.contentLoadURL", false);
SpecialPowers.setBoolPref("middlemouse.paste", false);
SpecialPowers.setBoolPref("general.autoScroll", false);
runNextTest();
}
function finish()
{
SpecialPowers.clearUserPref("middlemouse.contentLoadURL");
SpecialPowers.clearUserPref("middlemouse.paste");
SpecialPowers.clearUserPref("general.autoScroll");
SimpleTest.finish();
}
SimpleTest.waitForFocus(init);
</script>
</body>