mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1009388 part.1 Support getModifierState("Accel") r=smaug
This commit is contained in:
parent
849371302f
commit
442e0f0f31
@ -456,6 +456,9 @@ UIEvent::GetModifierStateInternal(const nsAString& aKey)
|
||||
{
|
||||
WidgetInputEvent* inputEvent = mEvent->AsInputEvent();
|
||||
MOZ_ASSERT(inputEvent, "mEvent must be WidgetInputEvent or derived class");
|
||||
if (aKey.EqualsLiteral("Accel")) {
|
||||
return inputEvent->IsAccel();
|
||||
}
|
||||
if (aKey.EqualsLiteral(NS_DOM_KEYNAME_SHIFT)) {
|
||||
return inputEvent->IsShift();
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ support-files =
|
||||
window_bug659071.html
|
||||
window_wheel_default_action.html
|
||||
|
||||
[test_accel_virtual_modifier.html]
|
||||
[test_addEventListenerExtraArg.html]
|
||||
[test_all_synthetic_events.html]
|
||||
[test_bug226361.xhtml]
|
||||
|
90
dom/events/test/test_accel_virtual_modifier.html
Normal file
90
dom/events/test/test_accel_virtual_modifier.html
Normal file
@ -0,0 +1,90 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for DOM "Accel" virtual modifier</title>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none">
|
||||
|
||||
</div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
|
||||
var kAccel = "Accel";
|
||||
var kAccelKeyCode = SpecialPowers.getIntPref("ui.key.accelKey");
|
||||
|
||||
var mouseEvent = new MouseEvent("mousedown", {});
|
||||
is(mouseEvent.getModifierState(kAccel), false,
|
||||
"MouseEvent.getModifierState(\"" + kAccel + "\") should be false");
|
||||
mouseEvent = new MouseEvent("wheel", { accelKey: true});
|
||||
is(mouseEvent.getModifierState(kAccel), false,
|
||||
"MouseEvent.getModifierState(\"" + kAccel + "\") should be false due to not supporting accelKey attribute");
|
||||
mouseEvent = new MouseEvent("mousedown", { ctrlKey: true });
|
||||
is(mouseEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_CONTROL,
|
||||
"MouseEvent.getModifierState(\"" + kAccel + "\") should be true if ctrlKey is an accel modifier");
|
||||
mouseEvent = new MouseEvent("mousedown", { altKey: true });
|
||||
is(mouseEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_ALT,
|
||||
"MouseEvent.getModifierState(\"" + kAccel + "\") should be true if altKey is an accel modifier");
|
||||
mouseEvent = new MouseEvent("mousedown", { metaKey: true });
|
||||
is(mouseEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_META,
|
||||
"MouseEvent.getModifierState(\"" + kAccel + "\") should be true if metaKey is an accel modifier");
|
||||
mouseEvent = new MouseEvent("mousedown", { ctrlKey: true, altKey: true, metaKey: true });
|
||||
is(mouseEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_CONTROL ||
|
||||
kAccelKeyCode == KeyboardEvent.DOM_VK_ALT ||
|
||||
kAccelKeyCode == KeyboardEvent.DOM_VK_META,
|
||||
"MouseEvent.getModifierState(\"" + kAccel + "\") should be true if one of ctrlKey, altKey or metaKey is an accel modifier");
|
||||
|
||||
var wheelEvent = new WheelEvent("wheel", {});
|
||||
is(wheelEvent.getModifierState(kAccel), false,
|
||||
"WheelEvent.getModifierState(\"" + kAccel + "\") should be false");
|
||||
wheelEvent = new WheelEvent("wheel", { accelKey: true});
|
||||
is(wheelEvent.getModifierState(kAccel), false,
|
||||
"WheelEvent.getModifierState(\"" + kAccel + "\") should be false due to not supporting accelKey attribute");
|
||||
wheelEvent = new WheelEvent("wheel", { ctrlKey: true });
|
||||
is(wheelEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_CONTROL,
|
||||
"WheelEvent.getModifierState(\"" + kAccel + "\") should be true if ctrlKey is an accel modifier");
|
||||
wheelEvent = new WheelEvent("wheel", { altKey: true });
|
||||
is(wheelEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_ALT,
|
||||
"WheelEvent.getModifierState(\"" + kAccel + "\") should be true if altKey is an accel modifier");
|
||||
wheelEvent = new WheelEvent("wheel", { metaKey: true });
|
||||
is(wheelEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_META,
|
||||
"WheelEvent.getModifierState(\"" + kAccel + "\") should be true if metaKey is an accel modifier");
|
||||
wheelEvent = new WheelEvent("wheel", { ctrlKey: true, altKey: true, metaKey: true });
|
||||
is(wheelEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_CONTROL ||
|
||||
kAccelKeyCode == KeyboardEvent.DOM_VK_ALT ||
|
||||
kAccelKeyCode == KeyboardEvent.DOM_VK_META,
|
||||
"WheelEvent.getModifierState(\"" + kAccel + "\") should be true if one of ctrlKey, altKey or metaKey is an accel modifier");
|
||||
|
||||
var keyboardEvent = new KeyboardEvent("keydown", {});
|
||||
is(keyboardEvent.getModifierState(kAccel), false,
|
||||
"KeyboardEvent.getModifierState(\"" + kAccel + "\") should be false");
|
||||
keyboardEvent = new KeyboardEvent("keydown", { accelKey: true});
|
||||
is(keyboardEvent.getModifierState(kAccel), false,
|
||||
"KeyboardEvent.getModifierState(\"" + kAccel + "\") should be false due to not supporting accelKey attribute");
|
||||
keyboardEvent = new KeyboardEvent("keydown", { ctrlKey: true });
|
||||
is(keyboardEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_CONTROL,
|
||||
"KeyboardEvent.getModifierState(\"" + kAccel + "\") should be true if ctrlKey is an accel modifier");
|
||||
keyboardEvent = new KeyboardEvent("keydown", { altKey: true });
|
||||
is(keyboardEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_ALT,
|
||||
"KeyboardEvent.getModifierState(\"" + kAccel + "\") should be true if altKey is an accel modifier");
|
||||
keyboardEvent = new KeyboardEvent("keydown", { metaKey: true });
|
||||
is(keyboardEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_META,
|
||||
"KeyboardEvent.getModifierState(\"" + kAccel + "\") should be true if metaKey is an accel modifier");
|
||||
keyboardEvent = new KeyboardEvent("keydown", { ctrlKey: true, altKey: true, metaKey: true });
|
||||
is(keyboardEvent.getModifierState(kAccel), kAccelKeyCode == KeyboardEvent.DOM_VK_CONTROL ||
|
||||
kAccelKeyCode == KeyboardEvent.DOM_VK_ALT ||
|
||||
kAccelKeyCode == KeyboardEvent.DOM_VK_META,
|
||||
"KeyboardEvent.getModifierState(\"" + kAccel + "\") should be true if one of ctrlKey, altKey or metaKey is an accel modifier");
|
||||
|
||||
// "Accel" virtual modifier must be supported with getModifierState(). So, any legacy init*Event()'s
|
||||
// modifiers list argument shouldn't accept "Accel".
|
||||
ok(typeof(KeyboardEvent.initKeyboardEvent) != "function",
|
||||
"If we would support KeyboardEvent.initKeyboardEvent, we should test its modifier list argument doesn't accept \"" + kAccel + "\"");
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -890,6 +890,7 @@ public:
|
||||
|
||||
enum Modifier
|
||||
{
|
||||
MODIFIER_NONE = 0x0000,
|
||||
MODIFIER_ALT = 0x0001,
|
||||
MODIFIER_ALTGRAPH = 0x0002,
|
||||
MODIFIER_CAPSLOCK = 0x0004,
|
||||
@ -963,6 +964,19 @@ public:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a modifier of "Accel" virtual modifier which is used for shortcut
|
||||
* key.
|
||||
*/
|
||||
static Modifier AccelModifier();
|
||||
|
||||
// true indicates the accel key on the environment is down
|
||||
bool IsAccel() const
|
||||
{
|
||||
return ((modifiers & AccelModifier()) != 0);
|
||||
}
|
||||
|
||||
// true indicates the shift key is down
|
||||
bool IsShift() const
|
||||
{
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "mozilla/InternalMutationEvent.h"
|
||||
#include "mozilla/MiscEvents.h"
|
||||
#include "mozilla/MouseEvents.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/TextEvents.h"
|
||||
#include "mozilla/TouchEvents.h"
|
||||
|
||||
@ -244,6 +245,41 @@ WidgetEvent::IsAllowedToDispatchDOMEvent() const
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* mozilla::WidgetInputEvent
|
||||
******************************************************************************/
|
||||
|
||||
/* static */
|
||||
Modifier
|
||||
WidgetInputEvent::AccelModifier()
|
||||
{
|
||||
static Modifier sAccelModifier = MODIFIER_NONE;
|
||||
if (sAccelModifier == MODIFIER_NONE) {
|
||||
switch (Preferences::GetInt("ui.key.accelKey", 0)) {
|
||||
case nsIDOMKeyEvent::DOM_VK_META:
|
||||
sAccelModifier = MODIFIER_META;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_WIN:
|
||||
sAccelModifier = MODIFIER_OS;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_ALT:
|
||||
sAccelModifier = MODIFIER_ALT;
|
||||
break;
|
||||
case nsIDOMKeyEvent::DOM_VK_CONTROL:
|
||||
sAccelModifier = MODIFIER_CONTROL;
|
||||
break;
|
||||
default:
|
||||
#ifdef XP_MACOSX
|
||||
sAccelModifier = MODIFIER_META;
|
||||
#else
|
||||
sAccelModifier = MODIFIER_CONTROL;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sAccelModifier;
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* mozilla::WidgetKeyboardEvent (TextEvents.h)
|
||||
******************************************************************************/
|
||||
|
Loading…
Reference in New Issue
Block a user