Bug 630811 part.6 Support new modifiers on all events derived from nsInputEvent on Cocoa r=smichaud

This commit is contained in:
Masayuki Nakano 2012-04-25 12:00:02 +09:00
parent 9de2f09ddc
commit 216eea36c9
4 changed files with 125 additions and 110 deletions

View File

@ -670,11 +670,7 @@ TISInputSourceWrapper::InitKeyEvent(NSEvent *aNativeKeyEvent,
aKeyEvent.time = PR_IntervalNow();
NSUInteger modifiers = [aNativeKeyEvent modifierFlags];
aKeyEvent.isShift = ((modifiers & NSShiftKeyMask) != 0);
aKeyEvent.isControl = ((modifiers & NSControlKeyMask) != 0);
aKeyEvent.isAlt = ((modifiers & NSAlternateKeyMask) != 0);
aKeyEvent.isMeta = ((modifiers & NSCommandKeyMask) != 0);
nsCocoaUtils::InitInputEvent(aKeyEvent, aNativeKeyEvent);
aKeyEvent.refPoint = nsIntPoint(0, 0);
aKeyEvent.isChar = false; // XXX not used in XP level
@ -689,8 +685,8 @@ TISInputSourceWrapper::InitKeyEvent(NSEvent *aNativeKeyEvent,
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TISInputSourceWrapper::InitKeyEvent, "
"shift=%s, ctrl=%s, alt=%s, meta=%s",
this, OnOrOff(aKeyEvent.isShift), OnOrOff(aKeyEvent.isControl),
OnOrOff(aKeyEvent.isAlt), OnOrOff(aKeyEvent.isMeta)));
this, OnOrOff(aKeyEvent.IsShift()), OnOrOff(aKeyEvent.IsControl()),
OnOrOff(aKeyEvent.IsAlt()), OnOrOff(aKeyEvent.IsMeta())));
if (aKeyEvent.message == NS_KEY_PRESS &&
!TextInputHandler::IsSpecialGeckoKey([aNativeKeyEvent keyCode])) {
@ -728,8 +724,8 @@ TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent,
}
// convert control-modified charCode to raw charCode (with appropriate case)
if (aKeyEvent.isControl && aKeyEvent.charCode <= 26) {
aKeyEvent.charCode += (aKeyEvent.isShift) ? ('A' - 1) : ('a' - 1);
if (aKeyEvent.IsControl() && aKeyEvent.charCode <= 26) {
aKeyEvent.charCode += (aKeyEvent.IsShift()) ? ('A' - 1) : ('a' - 1);
}
if (aKeyEvent.charCode != 0) {
@ -741,7 +737,7 @@ TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent,
"aKeyEvent.keyCode=0x%X, aKeyEvent.charCode=0x%X",
this, aKeyEvent.keyCode, aKeyEvent.charCode));
if (!aKeyEvent.isControl && !aKeyEvent.isMeta && !aKeyEvent.isAlt) {
if (!aKeyEvent.IsControl() && !aKeyEvent.IsMeta() && !aKeyEvent.IsAlt()) {
return;
}
@ -804,7 +800,7 @@ TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent,
// normal characters. These are the characters that the user is most
// likely to associate with this key.
if ((unshiftedChar || shiftedChar) &&
(!aKeyEvent.isMeta || !isDvorakQWERTY)) {
(!aKeyEvent.IsMeta() || !isDvorakQWERTY)) {
nsAlternativeCharCode altCharCodes(unshiftedChar, shiftedChar);
aKeyEvent.alternativeCharCodes.AppendElement(altCharCodes);
}
@ -812,7 +808,7 @@ TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent,
("%p TISInputSourceWrapper::InitKeyPressEvent, "
"aKeyEvent.isMeta=%s, isDvorakQWERTY=%s, "
"unshiftedChar=U+%X, shiftedChar=U+%X",
this, OnOrOff(aKeyEvent.isMeta), TrueOrFalse(isDvorakQWERTY),
this, OnOrOff(aKeyEvent.IsMeta()), TrueOrFalse(isDvorakQWERTY),
unshiftedChar, shiftedChar));
// Most keyboard layouts provide the same characters in the NSEvents
@ -866,10 +862,10 @@ TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent,
// keys are expected to be Latin characters.
//
// XXX We should do something similar when Control is down (bug 429510).
if (aKeyEvent.isMeta && !(aKeyEvent.isControl || aKeyEvent.isAlt)) {
if (aKeyEvent.IsMeta() && !(aKeyEvent.IsControl() || aKeyEvent.IsAlt())) {
// The character to use for charCode.
PRUint32 preferredCharCode = 0;
preferredCharCode = aKeyEvent.isShift ? cmdedShiftChar : cmdedChar;
preferredCharCode = aKeyEvent.IsShift() ? cmdedShiftChar : cmdedChar;
if (preferredCharCode) {
aKeyEvent.charCode = preferredCharCode;
@ -887,7 +883,7 @@ TISInputSourceWrapper::InitKeyPressEvent(NSEvent *aNativeKeyEvent,
// command key is pressed because when command key isn't pressed, uncmded
// chars have been appended already.
if ((cmdedChar || cmdedShiftChar) && isCmdSwitchLayout &&
(aKeyEvent.isMeta || !isDvorakQWERTY)) {
(aKeyEvent.IsMeta() || !isDvorakQWERTY)) {
nsAlternativeCharCode altCharCodes(cmdedChar, cmdedShiftChar);
aKeyEvent.alternativeCharCodes.AppendElement(altCharCodes);
}
@ -1054,8 +1050,7 @@ TextInputHandler::HandleKeyDownEvent(NSEvent* aNativeEvent)
nsMouseEvent contextMenuEvent(true, NS_CONTEXTMENU,
[mView widget], nsMouseEvent::eReal,
nsMouseEvent::eContextMenuKey);
contextMenuEvent.isShift = contextMenuEvent.isControl =
contextMenuEvent.isAlt = contextMenuEvent.isMeta = false;
contextMenuEvent.modifiers = 0;
bool cmEventHandled = DispatchEvent(contextMenuEvent);
PR_LOG(gLog, PR_LOG_ALWAYS,
@ -1339,7 +1334,6 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
// Dispatch keypress event with char instead of textEvent
nsKeyEvent keypressEvent(true, NS_KEY_PRESS, mWidget);
keypressEvent.time = PR_IntervalNow();
keypressEvent.charCode = str.CharAt(0);
keypressEvent.keyCode = 0;
keypressEvent.isChar = true;
@ -1355,6 +1349,7 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
if (currentKeyEvent) {
NSEvent* keyEvent = currentKeyEvent->mKeyEvent;
nsCocoaUtils::InitInputEvent(keypressEvent, keyEvent);
// XXX The ASCII characters inputting mode of egbridge (Japanese IME)
// might send the keyDown event with wrong keyboard layout if other
@ -1371,7 +1366,6 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
keypressEvent.flags |= NS_EVENT_FLAG_NO_DEFAULT;
}
keypressEvent.isShift = ([keyEvent modifierFlags] & NSShiftKeyMask) != 0;
if (!IsPrintableChar(keypressEvent.charCode)) {
keypressEvent.keyCode =
ComputeGeckoKeyCode([keyEvent keyCode],
@ -1379,6 +1373,7 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
keypressEvent.charCode = 0;
}
} else {
nsCocoaUtils::InitInputEvent(keypressEvent, static_cast<NSEvent*>(nsnull));
// Note that insertText is not called only at key pressing.
if (!IsPrintableChar(keypressEvent.charCode)) {
keypressEvent.keyCode =
@ -1387,6 +1382,12 @@ TextInputHandler::InsertText(NSAttributedString *aAttrString)
}
}
// Remove basic modifiers from keypress event because if they are included,
// nsPlaintextEditor ignores the event.
keypressEvent.modifiers &= ~(widget::MODIFIER_CONTROL |
widget::MODIFIER_ALT |
widget::MODIFIER_META);
// TODO:
// If mCurrentKeyEvent.mKeyEvent is null and when we implement textInput
// event of DOM3 Events, we should dispatch it instead of keypress event.
@ -3075,6 +3076,20 @@ PluginTextInputHandler::HandleCarbonPluginKeyEvent(EventRef aKeyEvent)
&modifiers);
NS_ENSURE_TRUE(status == noErr, );
NSUInteger cocoaModifiers = 0;
if (modifiers & shiftKey) {
cocoaModifiers |= NSShiftKeyMask;
}
if (modifiers & controlKey) {
cocoaModifiers |= NSControlKeyMask;
}
if (modifiers & optionKey) {
cocoaModifiers |= NSAlternateKeyMask;
}
if (modifiers & cmdKey) { // Should never happen
cocoaModifiers |= NSCommandKeyMask;
}
UInt32 macKeyCode;
status = ::GetEventParameter(aKeyEvent, kEventParamKeyCode,
typeUInt32, NULL, sizeof(macKeyCode), NULL,
@ -3090,6 +3105,7 @@ PluginTextInputHandler::HandleCarbonPluginKeyEvent(EventRef aKeyEvent)
EventRecord eventRec;
if (::ConvertEventRefToEventRecord(cloneEvent, &eventRec)) {
nsKeyEvent keydownEvent(true, NS_KEY_DOWN, mWidget);
nsCocoaUtils::InitInputEvent(keydownEvent, cocoaModifiers);
PRUint32 keyCode = ComputeGeckoKeyCode(macKeyCode, @"");
PRUint32 charCode(charCodes.ElementAt(i));
@ -3102,10 +3118,6 @@ PluginTextInputHandler::HandleCarbonPluginKeyEvent(EventRef aKeyEvent)
keydownEvent.charCode = charCode;
keydownEvent.isChar = true;
}
keydownEvent.isShift = ((modifiers & shiftKey) != 0);
keydownEvent.isControl = ((modifiers & controlKey) != 0);
keydownEvent.isAlt = ((modifiers & optionKey) != 0);
keydownEvent.isMeta = ((modifiers & cmdKey) != 0); // Should never happen
DispatchEvent(keydownEvent);
if (Destroyed()) {
break;
@ -3506,7 +3518,7 @@ TextInputHandlerBase::DispatchEvent(nsGUIEvent& aEvent)
{
if (aEvent.message == NS_KEY_PRESS) {
nsInputEvent& inputEvent = static_cast<nsInputEvent&>(aEvent);
if (!inputEvent.isMeta) {
if (!inputEvent.IsMeta()) {
PR_LOG(gLog, PR_LOG_ALWAYS,
("%p TextInputHandlerBase::DispatchEvent, hiding mouse cursor", this));
[NSCursor setHiddenUntilMouseMoves:YES];
@ -3816,7 +3828,7 @@ TextInputHandlerBase::IsSpecialGeckoKey(UInt32 aNativeKeyCode)
TextInputHandlerBase::IsNormalCharInputtingEvent(const nsKeyEvent& aKeyEvent)
{
// this is not character inputting event, simply.
if (!aKeyEvent.isChar || !aKeyEvent.charCode || aKeyEvent.isMeta) {
if (!aKeyEvent.isChar || !aKeyEvent.charCode || aKeyEvent.IsMeta()) {
return false;
}
// if this is unicode char inputting event, we don't need to check
@ -3825,7 +3837,7 @@ TextInputHandlerBase::IsNormalCharInputtingEvent(const nsKeyEvent& aKeyEvent)
return true;
}
// ASCII chars should be inputted without ctrl/alt/command keys
return !aKeyEvent.isControl && !aKeyEvent.isAlt;
return !aKeyEvent.IsControl() && !aKeyEvent.IsAlt();
}
/* static */ bool

View File

@ -153,9 +153,6 @@ PRUint32 nsChildView::sLastInputEventCount = 0;
- (id)initWithFrame:(NSRect)inFrame geckoChild:(nsChildView*)inChild;
- (void)forceRefreshOpenGL;
// do generic gecko event setup with a generic cocoa event. accepts nil inEvent.
- (void) convertGenericCocoaEvent:(NSEvent*)inEvent toGeckoEvent:(nsInputEvent*)outGeckoEvent;
// set up a gecko mouse event based on a cocoa mouse event
- (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent toGeckoEvent:(nsInputEvent*)outGeckoEvent;
@ -3241,7 +3238,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
NSUInteger modifierFlags = [theEvent modifierFlags];
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
NSInteger clickCount = [theEvent clickCount];
@ -3309,7 +3306,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
#endif // ifndef NP_NO_CARBON
NPCocoaEvent cocoaEvent;
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
if ([theEvent modifierFlags] & NSControlKeyMask)
geckoEvent.button = nsMouseEvent::eRightButton;
@ -3358,7 +3355,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
#endif
{
if (ChildViewMouseTracker::ViewForEvent(theEvent) != self) {
nsMouseEvent geckoExitEvent(true, NS_MOUSE_EXIT, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoExitEvent(true, NS_MOUSE_EXIT, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoExitEvent];
NPCocoaEvent cocoaEvent;
@ -3442,7 +3439,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return;
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
// Create event for use by plugins.
@ -3497,7 +3494,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
#endif // ifndef NP_NO_CARBON
NPCocoaEvent cocoaEvent;
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
// create event for use by plugins
@ -3550,7 +3547,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
return;
// The right mouse went down, fire off a right mouse down event to gecko
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.button = nsMouseEvent::eRightButton;
geckoEvent.clickCount = [theEvent clickCount];
@ -3605,7 +3602,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
#endif // ifndef NP_NO_CARBON
NPCocoaEvent cocoaEvent;
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.button = nsMouseEvent::eRightButton;
geckoEvent.clickCount = [theEvent clickCount];
@ -3649,7 +3646,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return;
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.button = nsMouseEvent::eRightButton;
@ -3671,7 +3668,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return;
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_DOWN, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.button = nsMouseEvent::eMiddleButton;
geckoEvent.clickCount = [theEvent clickCount];
@ -3686,7 +3683,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return;
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_BUTTON_UP, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.button = nsMouseEvent::eMiddleButton;
@ -3698,7 +3695,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return;
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_MOVE, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.button = nsMouseEvent::eMiddleButton;
@ -3759,7 +3756,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (scrollDelta != 0) {
// Send the line scroll event.
nsMouseScrollEvent geckoEvent(true, NS_MOUSE_SCROLL, nsnull);
nsMouseScrollEvent geckoEvent(true, NS_MOUSE_SCROLL, mGeckoChild);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.scrollFlags |= inAxis;
@ -3851,7 +3848,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (hasPixels) {
// Send the pixel scroll event.
nsMouseScrollEvent geckoEvent(true, NS_MOUSE_PIXEL_SCROLL, nsnull);
nsMouseScrollEvent geckoEvent(true, NS_MOUSE_PIXEL_SCROLL, mGeckoChild);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.scrollFlags |= inAxis;
if (isMomentumScroll)
@ -3915,7 +3912,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
return nil;
}
nsMouseEvent geckoEvent(true, NS_CONTEXTMENU, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_CONTEXTMENU, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:theEvent toGeckoEvent:&geckoEvent];
geckoEvent.button = nsMouseEvent::eRightButton;
mGeckoChild->DispatchWindowEvent(geckoEvent);
@ -3943,29 +3940,6 @@ NSEvent* gLastDragMouseDownEvent = nil;
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
}
// Basic conversion for cocoa to gecko events, common to all conversions.
// Note that it is OK for inEvent to be nil.
- (void) convertGenericCocoaEvent:(NSEvent*)inEvent toGeckoEvent:(nsInputEvent*)outGeckoEvent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NS_ASSERTION(outGeckoEvent, "convertGenericCocoaEvent:toGeckoEvent: requires non-null outGeckoEvent");
if (!outGeckoEvent)
return;
outGeckoEvent->widget = [self widget];
outGeckoEvent->time = PR_IntervalNow();
NSUInteger modifiers =
inEvent ? [inEvent modifierFlags] : ::GetCurrentKeyModifiers();
outGeckoEvent->isShift = ((modifiers & NSShiftKeyMask) != 0);
outGeckoEvent->isControl = ((modifiers & NSControlKeyMask) != 0);
outGeckoEvent->isAlt = ((modifiers & NSAlternateKeyMask) != 0);
outGeckoEvent->isMeta = ((modifiers & NSCommandKeyMask) != 0);
NS_OBJC_END_TRY_ABORT_BLOCK;
}
- (void) convertCocoaMouseEvent:(NSEvent*)aMouseEvent toGeckoEvent:(nsInputEvent*)outGeckoEvent
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
@ -3974,7 +3948,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!outGeckoEvent)
return;
[self convertGenericCocoaEvent:aMouseEvent toGeckoEvent:outGeckoEvent];
nsCocoaUtils::InitInputEvent(*outGeckoEvent, aMouseEvent);
// convert point to view coordinate system
NSPoint locationInWindow = nsCocoaUtils::EventLocationForWindow(aMouseEvent, [self window]);
@ -3982,48 +3956,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
outGeckoEvent->refPoint.x = static_cast<nscoord>(localPoint.x);
outGeckoEvent->refPoint.y = static_cast<nscoord>(localPoint.y);
nsMouseEvent_base* mouseEvent =
static_cast<nsMouseEvent_base*>(outGeckoEvent);
NSUInteger modifiers =
aMouseEvent ? [aMouseEvent modifierFlags] : ::GetCurrentKeyModifiers();
mouseEvent->modifiers = 0;
if (mouseEvent->isShift) {
mouseEvent->modifiers |= MODIFIER_SHIFT;
}
if (mouseEvent->isControl) {
mouseEvent->modifiers |= MODIFIER_CONTROL;
}
if (mouseEvent->isAlt) {
mouseEvent->modifiers |= 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.
mouseEvent->modifiers |= MODIFIER_ALTGRAPH;
}
if (mouseEvent->isMeta) {
mouseEvent->modifiers |= MODIFIER_META;
}
if (modifiers & NSAlphaShiftKeyMask) {
mouseEvent->modifiers |= 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
// a keyboard which doesn't have numpad, e.g., MacBook's keyboard, we can
// assume that NumLock is always unlocked.
// Unfortunately, we cannot know whether current keyboard has numpad or not.
// 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 (modifiers & NSNumericPadKeyMask) {
mouseEvent->modifiers |= 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.
mouseEvent->buttons = 0;
NSUInteger mouseButtons =
nsToolkit::OnSnowLeopardOrLater() ? [NSEvent pressedMouseButtons] : 0;
@ -4281,7 +4215,7 @@ NSEvent* gLastDragMouseDownEvent = nil;
if (!mGeckoChild)
return YES;
nsMouseEvent geckoEvent(true, NS_MOUSE_ACTIVATE, nsnull, nsMouseEvent::eReal);
nsMouseEvent geckoEvent(true, NS_MOUSE_ACTIVATE, mGeckoChild, nsMouseEvent::eReal);
[self convertCocoaMouseEvent:aEvent toGeckoEvent:&geckoEvent];
return !mGeckoChild->DispatchWindowEvent(geckoEvent);
}
@ -4524,8 +4458,8 @@ NSEvent* gLastDragMouseDownEvent = nil;
}
// set up gecko event
nsDragEvent geckoEvent(true, aMessage, nsnull);
[self convertGenericCocoaEvent:[NSApp currentEvent] toGeckoEvent:&geckoEvent];
nsDragEvent geckoEvent(true, aMessage, mGeckoChild);
nsCocoaUtils::InitInputEvent(geckoEvent, [NSApp currentEvent]);
// Use our own coordinates in the gecko event.
// Convert event from gecko global coords to gecko view coords.

View File

@ -213,6 +213,13 @@ class nsCocoaUtils
*/
static void InitPluginEvent(nsPluginEvent &aPluginEvent,
NPCocoaEvent &aCocoaEvent);
/**
* Initializes nsInputEvent for aNativeEvent or aModifiers.
*/
static void InitInputEvent(nsInputEvent &aInputEvent,
NSEvent* aNativeEvent);
static void InitInputEvent(nsInputEvent &aInputEvent,
NSUInteger aModifiers);
};
#endif // nsCocoaUtils_h_

View File

@ -53,6 +53,8 @@
#include "nsToolkit.h"
#include "nsGUIEvent.h"
using namespace mozilla::widget;
float nsCocoaUtils::MenuBarScreenHeight()
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_RETURN;
@ -415,3 +417,63 @@ nsCocoaUtils::InitPluginEvent(nsPluginEvent &aPluginEvent,
aPluginEvent.pluginEvent = (void*)&aCocoaEvent;
aPluginEvent.retargetToFocusedDocument = false;
}
// static
void
nsCocoaUtils::InitInputEvent(nsInputEvent &aInputEvent,
NSEvent* aNativeEvent)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
NSUInteger modifiers =
aNativeEvent ? [aNativeEvent modifierFlags] : ::GetCurrentKeyModifiers();
InitInputEvent(aInputEvent, modifiers);
aInputEvent.time = PR_IntervalNow();
NS_OBJC_END_TRY_ABORT_BLOCK;
}
// static
void
nsCocoaUtils::InitInputEvent(nsInputEvent &aInputEvent,
NSUInteger aModifiers)
{
aInputEvent.modifiers = 0;
if (aModifiers & NSShiftKeyMask) {
aInputEvent.modifiers |= MODIFIER_SHIFT;
}
if (aModifiers & NSControlKeyMask) {
aInputEvent.modifiers |= MODIFIER_CONTROL;
}
if (aModifiers & NSAlternateKeyMask) {
aInputEvent.modifiers |= 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;
}
if (aModifiers & NSCommandKeyMask) {
aInputEvent.modifiers |= MODIFIER_META;
}
if (aModifiers & NSAlphaShiftKeyMask) {
aInputEvent.modifiers |= 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
// a keyboard which doesn't have numpad, e.g., MacBook's keyboard, we can
// assume that NumLock is always unlocked.
// Unfortunately, we cannot know whether current keyboard has numpad or not.
// 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;
}
// 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.
}