mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 05:11:16 +00:00
Bug 1124608 Support D3E EventModifierInit r=smaug
This commit is contained in:
parent
5c5b8c9484
commit
db9a97210a
@ -255,9 +255,9 @@ KeyboardEvent::InitWithKeyboardEventInit(EventTarget* aOwner,
|
||||
{
|
||||
bool trusted = Init(aOwner);
|
||||
aRv = InitKeyEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
||||
aParam.mView, aParam.mCtrlKey, aParam.mAltKey,
|
||||
aParam.mShiftKey, aParam.mMetaKey,
|
||||
aParam.mView, false, false, false, false,
|
||||
aParam.mKeyCode, aParam.mCharCode);
|
||||
InitModifiers(aParam);
|
||||
SetTrusted(trusted);
|
||||
mDetail = aParam.mDetail;
|
||||
mInitializedByCtor = true;
|
||||
|
@ -152,20 +152,11 @@ MouseEvent::Constructor(const GlobalObject& aGlobal,
|
||||
aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
|
||||
aParam.mMetaKey, aParam.mButton, aParam.mRelatedTarget,
|
||||
aRv);
|
||||
e->InitModifiers(aParam);
|
||||
e->SetTrusted(trusted);
|
||||
|
||||
switch (e->mEvent->mClass) {
|
||||
case eMouseEventClass:
|
||||
case eMouseScrollEventClass:
|
||||
case eWheelEventClass:
|
||||
case eDragEventClass:
|
||||
case ePointerEventClass:
|
||||
case eSimpleGestureEventClass:
|
||||
e->mEvent->AsMouseEventBase()->buttons = aParam.mButtons;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
MOZ_RELEASE_ASSERT(e->mEvent->AsMouseEventBase(),
|
||||
"mEvent of MouseEvent must inherit WidgetMouseEventBase");
|
||||
e->mEvent->AsMouseEventBase()->buttons = aParam.mButtons;
|
||||
|
||||
return e.forget();
|
||||
}
|
||||
|
@ -79,9 +79,9 @@ PointerEvent::Constructor(EventTarget* aOwner,
|
||||
e->InitMouseEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
||||
aParam.mView, aParam.mDetail, aParam.mScreenX,
|
||||
aParam.mScreenY, aParam.mClientX, aParam.mClientY,
|
||||
aParam.mCtrlKey, aParam.mAltKey, aParam.mShiftKey,
|
||||
aParam.mMetaKey, aParam.mButton,
|
||||
false, false, false, false, aParam.mButton,
|
||||
aParam.mRelatedTarget);
|
||||
e->InitModifiers(aParam);
|
||||
|
||||
WidgetPointerEvent* widgetEvent = e->mEvent->AsPointerEvent();
|
||||
widgetEvent->pointerId = aParam.mPointerId;
|
||||
|
@ -455,6 +455,43 @@ UIEvent::GetModifierStateInternal(const nsAString& aKey)
|
||||
return ((inputEvent->modifiers & WidgetInputEvent::GetModifier(aKey)) != 0);
|
||||
}
|
||||
|
||||
void
|
||||
UIEvent::InitModifiers(const EventModifierInit& aParam)
|
||||
{
|
||||
if (NS_WARN_IF(!mEvent)) {
|
||||
return;
|
||||
}
|
||||
WidgetInputEvent* inputEvent = mEvent->AsInputEvent();
|
||||
MOZ_ASSERT(inputEvent,
|
||||
"This method shouldn't be called if it doesn't have modifiers");
|
||||
if (NS_WARN_IF(!inputEvent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
inputEvent->modifiers = MODIFIER_NONE;
|
||||
|
||||
#define SET_MODIFIER(aName, aValue) \
|
||||
if (aParam.m##aName) { \
|
||||
inputEvent->modifiers |= aValue; \
|
||||
} \
|
||||
|
||||
SET_MODIFIER(CtrlKey, MODIFIER_CONTROL)
|
||||
SET_MODIFIER(ShiftKey, MODIFIER_SHIFT)
|
||||
SET_MODIFIER(AltKey, MODIFIER_ALT)
|
||||
SET_MODIFIER(MetaKey, MODIFIER_META)
|
||||
SET_MODIFIER(ModifierAltGraph, MODIFIER_ALTGRAPH)
|
||||
SET_MODIFIER(ModifierCapsLock, MODIFIER_CAPSLOCK)
|
||||
SET_MODIFIER(ModifierFn, MODIFIER_FN)
|
||||
SET_MODIFIER(ModifierFnLock, MODIFIER_FNLOCK)
|
||||
SET_MODIFIER(ModifierNumLock, MODIFIER_NUMLOCK)
|
||||
SET_MODIFIER(ModifierOS, MODIFIER_OS)
|
||||
SET_MODIFIER(ModifierScrollLock, MODIFIER_SCROLLLOCK)
|
||||
SET_MODIFIER(ModifierSymbol, MODIFIER_SYMBOL)
|
||||
SET_MODIFIER(ModifierSymbolLock, MODIFIER_SYMBOLLOCK)
|
||||
|
||||
#undef SET_MODIFIER
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
|
@ -168,6 +168,7 @@ protected:
|
||||
|
||||
static Modifiers ComputeModifierState(const nsAString& aModifiersList);
|
||||
bool GetModifierStateInternal(const nsAString& aKey);
|
||||
void InitModifiers(const EventModifierInit& aParam);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -148,33 +148,6 @@ WheelEvent::GetDeltaMode(uint32_t* aDeltaMode)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
GetModifierList(bool aCtrl, bool aShift, bool aAlt, bool aMeta,
|
||||
nsAString& aModifierList)
|
||||
{
|
||||
if (aCtrl) {
|
||||
aModifierList.AppendLiteral(NS_DOM_KEYNAME_CONTROL);
|
||||
}
|
||||
if (aShift) {
|
||||
if (!aModifierList.IsEmpty()) {
|
||||
aModifierList.Append(' ');
|
||||
}
|
||||
aModifierList.AppendLiteral(NS_DOM_KEYNAME_SHIFT);
|
||||
}
|
||||
if (aAlt) {
|
||||
if (!aModifierList.IsEmpty()) {
|
||||
aModifierList.Append(' ');
|
||||
}
|
||||
aModifierList.AppendLiteral(NS_DOM_KEYNAME_ALT);
|
||||
}
|
||||
if (aMeta) {
|
||||
if (!aModifierList.IsEmpty()) {
|
||||
aModifierList.Append(' ');
|
||||
}
|
||||
aModifierList.AppendLiteral(NS_DOM_KEYNAME_META);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<WheelEvent>
|
||||
WheelEvent::Constructor(const GlobalObject& aGlobal,
|
||||
const nsAString& aType,
|
||||
@ -184,17 +157,14 @@ WheelEvent::Constructor(const GlobalObject& aGlobal,
|
||||
nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
|
||||
nsRefPtr<WheelEvent> e = new WheelEvent(t, nullptr, nullptr);
|
||||
bool trusted = e->Init(t);
|
||||
nsAutoString modifierList;
|
||||
GetModifierList(aParam.mCtrlKey, aParam.mShiftKey,
|
||||
aParam.mAltKey, aParam.mMetaKey,
|
||||
modifierList);
|
||||
aRv = e->InitWheelEvent(aType, aParam.mBubbles, aParam.mCancelable,
|
||||
aParam.mView, aParam.mDetail,
|
||||
aParam.mScreenX, aParam.mScreenY,
|
||||
aParam.mClientX, aParam.mClientY,
|
||||
aParam.mButton, aParam.mRelatedTarget,
|
||||
modifierList, aParam.mDeltaX,
|
||||
EmptyString(), aParam.mDeltaX,
|
||||
aParam.mDeltaY, aParam.mDeltaZ, aParam.mDeltaMode);
|
||||
e->InitModifiers(aParam);
|
||||
e->mEvent->AsWheelEvent()->buttons = aParam.mButtons;
|
||||
e->SetTrusted(trusted);
|
||||
return e.forget();
|
||||
|
@ -22,6 +22,19 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=675884
|
||||
var receivedEvent;
|
||||
document.addEventListener("hello", function(e) { receivedEvent = e; }, true);
|
||||
|
||||
function isMethodResultInitializer(aPropName)
|
||||
{
|
||||
return aPropName.startsWith("modifier");
|
||||
}
|
||||
|
||||
function getPropValue(aEvent, aPropName)
|
||||
{
|
||||
if (aPropName.startsWith("modifier")) {
|
||||
return aEvent.getModifierState(aPropName.substr("modifier".length));
|
||||
}
|
||||
return aEvent[aPropName];
|
||||
}
|
||||
|
||||
// Event
|
||||
var e;
|
||||
var ex = false;
|
||||
@ -371,6 +384,15 @@ var keyboardEventProps =
|
||||
{ shiftKey: false },
|
||||
{ altKey: false },
|
||||
{ metaKey: false },
|
||||
{ modifierAltGraph: false },
|
||||
{ modifierCapsLock: false },
|
||||
{ modifierFn: false },
|
||||
{ modifierFnLock: false },
|
||||
{ modifierNumLock: false },
|
||||
{ modifierOS: false },
|
||||
{ modifierScrollLock: false },
|
||||
{ modifierSymbol: false },
|
||||
{ modifierSymbolLock: false },
|
||||
{ repeat: false },
|
||||
{ isComposing: false },
|
||||
{ charCode: 0 },
|
||||
@ -391,6 +413,15 @@ var testKeyboardProps =
|
||||
{ shiftKey: true },
|
||||
{ altKey: true },
|
||||
{ metaKey: true },
|
||||
{ modifierAltGraph: true },
|
||||
{ modifierCapsLock: true },
|
||||
{ modifierFn: true },
|
||||
{ modifierFnLock: true },
|
||||
{ modifierNumLock: true },
|
||||
{ modifierOS: true },
|
||||
{ modifierScrollLock: true },
|
||||
{ modifierSymbol: true },
|
||||
{ modifierSymbolLock: true },
|
||||
{ repeat: true },
|
||||
{ isComposing: true },
|
||||
{ charCode: 2 },
|
||||
@ -409,7 +440,9 @@ for (var i = 0; i < keyboardEventProps.length; ++i) {
|
||||
if (!codeEnabled && prop == "code") {
|
||||
continue;
|
||||
}
|
||||
ok(prop in e, "keyboardEvent: KeyboardEvent doesn't have property " + prop + "!");
|
||||
if (!isMethodResultInitializer(prop)) {
|
||||
ok(prop in e, "keyboardEvent: KeyboardEvent doesn't have property " + prop + "!");
|
||||
}
|
||||
defaultKeyboardEventValues[prop] = keyboardEventProps[i][prop];
|
||||
}
|
||||
}
|
||||
@ -422,10 +455,10 @@ while (testKeyboardProps.length) {
|
||||
continue;
|
||||
}
|
||||
if (!(def in p)) {
|
||||
is(e[def], defaultKeyboardEventValues[def],
|
||||
is(getPropValue(e, def), defaultKeyboardEventValues[def],
|
||||
"KeyboardEvent: Wrong default value for " + def + "!");
|
||||
} else {
|
||||
is(e[def], p[def],
|
||||
is(getPropValue(e, def), p[def],
|
||||
"KeyboardEvent: Wrong event init value for " + def + "!");
|
||||
}
|
||||
}
|
||||
@ -680,6 +713,15 @@ var mouseEventProps =
|
||||
{ shiftKey: false },
|
||||
{ altKey: false },
|
||||
{ metaKey: false },
|
||||
{ modifierAltGraph: false },
|
||||
{ modifierCapsLock: false },
|
||||
{ modifierFn: false },
|
||||
{ modifierFnLock: false },
|
||||
{ modifierNumLock: false },
|
||||
{ modifierOS: false },
|
||||
{ modifierScrollLock: false },
|
||||
{ modifierSymbol: false },
|
||||
{ modifierSymbolLock: false },
|
||||
{ button: 0 },
|
||||
{ buttons: 0 },
|
||||
{ relatedTarget: null }
|
||||
@ -695,6 +737,15 @@ var testProps =
|
||||
{ shiftKey: true },
|
||||
{ altKey: true },
|
||||
{ metaKey: true },
|
||||
{ modifierAltGraph: true },
|
||||
{ modifierCapsLock: true },
|
||||
{ modifierFn: true },
|
||||
{ modifierFnLock: true },
|
||||
{ modifierNumLock: true },
|
||||
{ modifierOS: true },
|
||||
{ modifierScrollLock: true },
|
||||
{ modifierSymbol: true },
|
||||
{ modifierSymbolLock: true },
|
||||
{ button: 5 },
|
||||
{ buttons: 6 },
|
||||
{ relatedTarget: window }
|
||||
@ -703,7 +754,9 @@ var testProps =
|
||||
var defaultMouseEventValues = {};
|
||||
for (var i = 0; i < mouseEventProps.length; ++i) {
|
||||
for (prop in mouseEventProps[i]) {
|
||||
ok(prop in e, "MouseEvent: MouseEvent doesn't have property " + prop + "!");
|
||||
if (!isMethodResultInitializer(prop)) {
|
||||
ok(prop in e, "MouseEvent: MouseEvent doesn't have property " + prop + "!");
|
||||
}
|
||||
defaultMouseEventValues[prop] = mouseEventProps[i][prop];
|
||||
}
|
||||
}
|
||||
@ -713,10 +766,10 @@ while (testProps.length) {
|
||||
e = new MouseEvent("foo", p);
|
||||
for (var def in defaultMouseEventValues) {
|
||||
if (!(def in p)) {
|
||||
is(e[def], defaultMouseEventValues[def],
|
||||
is(getPropValue(e, def), defaultMouseEventValues[def],
|
||||
"MouseEvent: Wrong default value for " + def + "!");
|
||||
} else {
|
||||
is(e[def], p[def], "MouseEvent: Wrong event init value for " + def + "!");
|
||||
is(getPropValue(e, def), p[def], "MouseEvent: Wrong event init value for " + def + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -775,6 +828,15 @@ var wheelEventProps =
|
||||
{ shiftKey: false },
|
||||
{ altKey: false },
|
||||
{ metaKey: false },
|
||||
{ modifierAltGraph: false },
|
||||
{ modifierCapsLock: false },
|
||||
{ modifierFn: false },
|
||||
{ modifierFnLock: false },
|
||||
{ modifierNumLock: false },
|
||||
{ modifierOS: false },
|
||||
{ modifierScrollLock: false },
|
||||
{ modifierSymbol: false },
|
||||
{ modifierSymbolLock: false },
|
||||
{ button: 0 },
|
||||
{ buttons: 0 },
|
||||
{ relatedTarget: null },
|
||||
@ -794,6 +856,15 @@ var testWheelProps =
|
||||
{ shiftKey: true },
|
||||
{ altKey: true },
|
||||
{ metaKey: true },
|
||||
{ modifierAltGraph: true },
|
||||
{ modifierCapsLock: true },
|
||||
{ modifierFn: true },
|
||||
{ modifierFnLock: true },
|
||||
{ modifierNumLock: true },
|
||||
{ modifierOS: true },
|
||||
{ modifierScrollLock: true },
|
||||
{ modifierSymbol: true },
|
||||
{ modifierSymbolLock: true },
|
||||
{ button: 5 },
|
||||
{ buttons: 6 },
|
||||
{ relatedTarget: window },
|
||||
@ -806,7 +877,9 @@ var testWheelProps =
|
||||
var defaultWheelEventValues = {};
|
||||
for (var i = 0; i < wheelEventProps.length; ++i) {
|
||||
for (prop in wheelEventProps[i]) {
|
||||
ok(prop in e, "WheelEvent: WheelEvent doesn't have property " + prop + "!");
|
||||
if (!isMethodResultInitializer(prop)) {
|
||||
ok(prop in e, "WheelEvent: WheelEvent doesn't have property " + prop + "!");
|
||||
}
|
||||
defaultWheelEventValues[prop] = wheelEventProps[i][prop];
|
||||
}
|
||||
}
|
||||
@ -816,10 +889,10 @@ while (testWheelProps.length) {
|
||||
e = new WheelEvent("foo", p);
|
||||
for (var def in defaultWheelEventValues) {
|
||||
if (!(def in p)) {
|
||||
is(e[def], defaultWheelEventValues[def],
|
||||
is(getPropValue(e, def), defaultWheelEventValues[def],
|
||||
"WheelEvent: Wrong default value for " + def + "!");
|
||||
} else {
|
||||
is(e[def], p[def], "WheelEvent: Wrong event init value for " + def + "!");
|
||||
is(getPropValue(e, def), p[def], "WheelEvent: Wrong event init value for " + def + "!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,15 +31,11 @@ interface KeyboardEvent : UIEvent
|
||||
readonly attribute DOMString code;
|
||||
};
|
||||
|
||||
dictionary KeyboardEventInit : UIEventInit
|
||||
dictionary KeyboardEventInit : EventModifierInit
|
||||
{
|
||||
DOMString key = "";
|
||||
DOMString code = "";
|
||||
unsigned long location = 0;
|
||||
boolean ctrlKey = false;
|
||||
boolean shiftKey = false;
|
||||
boolean altKey = false;
|
||||
boolean metaKey = false;
|
||||
boolean repeat = false;
|
||||
boolean isComposing = false;
|
||||
|
||||
|
@ -54,16 +54,12 @@ partial interface MouseEvent
|
||||
};
|
||||
|
||||
// Suggested initMouseEvent replacement initializer:
|
||||
dictionary MouseEventInit : UIEventInit {
|
||||
dictionary MouseEventInit : EventModifierInit {
|
||||
// Attributes for MouseEvent:
|
||||
long screenX = 0;
|
||||
long screenY = 0;
|
||||
long clientX = 0;
|
||||
long clientY = 0;
|
||||
boolean ctrlKey = false;
|
||||
boolean shiftKey = false;
|
||||
boolean altKey = false;
|
||||
boolean metaKey = false;
|
||||
short button = 0;
|
||||
// Note: "buttons" was not previously initializable through initMouseEvent!
|
||||
unsigned short buttons = 0;
|
||||
|
@ -43,3 +43,23 @@ dictionary UIEventInit : EventInit
|
||||
Window? view = null;
|
||||
long detail = 0;
|
||||
};
|
||||
|
||||
// NOTE: Gecko doesn't support commented out modifiers yet.
|
||||
dictionary EventModifierInit : UIEventInit
|
||||
{
|
||||
boolean ctrlKey = false;
|
||||
boolean shiftKey = false;
|
||||
boolean altKey = false;
|
||||
boolean metaKey = false;
|
||||
boolean modifierAltGraph = false;
|
||||
boolean modifierCapsLock = false;
|
||||
boolean modifierFn = false;
|
||||
boolean modifierFnLock = false;
|
||||
// boolean modifierHyper = false;
|
||||
boolean modifierNumLock = false;
|
||||
boolean modifierOS = false;
|
||||
boolean modifierScrollLock = false;
|
||||
// boolean modifierSuper = false;
|
||||
boolean modifierSymbol = false;
|
||||
boolean modifierSymbolLock = false;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user