Bug 1193062 - Add nsCocoaUtils::ModifiersForEvent. r=smichaud

--HG--
extra : commitid : 8Aar2flB2na
extra : rebase_source : ba35da1d8d1fca49d98b8bc89b507d0105fe43db
extra : histedit_source : bb55f824f1a227a24b82eaf47c79175849649416
This commit is contained in:
Markus Stange 2015-07-21 18:41:08 -04:00
parent 4d793f82dd
commit b00a4d2055
2 changed files with 26 additions and 23 deletions

View File

@ -327,8 +327,12 @@ public:
*/
static void InitInputEvent(mozilla::WidgetInputEvent &aInputEvent,
NSEvent* aNativeEvent);
static void InitInputEvent(mozilla::WidgetInputEvent &aInputEvent,
NSUInteger aModifiers);
/**
* Converts the native modifiers from aNativeEvent into WidgetMouseEvent
* Modifiers. aNativeEvent can be null.
*/
static mozilla::Modifiers ModifiersForEvent(NSEvent* aNativeEvent);
/**
* ConvertToCarbonModifier() returns carbon modifier flags for the cocoa

View File

@ -598,40 +598,38 @@ nsCocoaUtils::InitInputEvent(WidgetInputEvent& aInputEvent,
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NSUInteger modifiers =
aNativeEvent ? [aNativeEvent modifierFlags] : [NSEvent modifierFlags];
InitInputEvent(aInputEvent, modifiers);
aInputEvent.modifiers = ModifiersForEvent(aNativeEvent);
aInputEvent.time = PR_IntervalNow();
NS_OBJC_END_TRY_ABORT_BLOCK;
}
// static
void
nsCocoaUtils::InitInputEvent(WidgetInputEvent& aInputEvent,
NSUInteger aModifiers)
Modifiers
nsCocoaUtils::ModifiersForEvent(NSEvent* aNativeEvent)
{
aInputEvent.modifiers = 0;
if (aModifiers & NSShiftKeyMask) {
aInputEvent.modifiers |= MODIFIER_SHIFT;
NSUInteger modifiers =
aNativeEvent ? [aNativeEvent modifierFlags] : [NSEvent modifierFlags];
Modifiers result = 0;
if (modifiers & NSShiftKeyMask) {
result |= MODIFIER_SHIFT;
}
if (aModifiers & NSControlKeyMask) {
aInputEvent.modifiers |= MODIFIER_CONTROL;
if (modifiers & NSControlKeyMask) {
result |= MODIFIER_CONTROL;
}
if (aModifiers & NSAlternateKeyMask) {
aInputEvent.modifiers |= MODIFIER_ALT;
if (modifiers & NSAlternateKeyMask) {
result |= MODIFIER_ALT;
// Mac's option key is similar to other platforms' AltGr key.
// Let's set AltGr flag when option key is pressed for consistency with
// other platforms.
aInputEvent.modifiers |= MODIFIER_ALTGRAPH;
result |= MODIFIER_ALTGRAPH;
}
if (aModifiers & NSCommandKeyMask) {
aInputEvent.modifiers |= MODIFIER_META;
if (modifiers & NSCommandKeyMask) {
result |= MODIFIER_META;
}
if (aModifiers & NSAlphaShiftKeyMask) {
aInputEvent.modifiers |= MODIFIER_CAPSLOCK;
if (modifiers & NSAlphaShiftKeyMask) {
result |= MODIFIER_CAPSLOCK;
}
// Mac doesn't have NumLock key. We can assume that NumLock is always locked
// if user is using a keyboard which has numpad. Otherwise, if user is using
@ -641,14 +639,15 @@ nsCocoaUtils::InitInputEvent(WidgetInputEvent& aInputEvent,
// We should notify locked state only when keys in numpad are pressed.
// By this, web applications may not be confused by unexpected numpad key's
// key event with unlocked state.
if (aModifiers & NSNumericPadKeyMask) {
aInputEvent.modifiers |= MODIFIER_NUMLOCK;
if (modifiers & NSNumericPadKeyMask) {
result |= MODIFIER_NUMLOCK;
}
// Be aware, NSFunctionKeyMask is included when arrow keys, home key or some
// other keys are pressed. We cannot check whether 'fn' key is pressed or
// not by the flag.
return result;
}
// static