Cocoa: Fix function key handling

Cocoa sends function keys (e.g. arrow keys, backspace, F1-F35, etc.) as
Unicode characters in the U+F700-U+F8FF range. Do not deliver text for
events that contain a single control character (to match Qt 4 behavior).
With this fix, keyboard navigation works again in Qt Creator when
running against Qt 5.

Change-Id: I5854bf713c2855dbc5ee491bace2f9dc1acd9426
Reviewed-by: Morten Johan Sørvig <morten.sorvig@nokia.com>
This commit is contained in:
Bradley T. Hughes 2012-03-16 12:32:37 +01:00 committed by Qt by Nokia
parent 60c59b5cf5
commit 4dbce2a469

View File

@ -572,16 +572,21 @@ static QTouchDevice *touchDevice = 0;
- (void)handleKeyEvent:(NSEvent *)nsevent eventType:(int)eventType
{
NSTimeInterval timestamp = [nsevent timestamp];
ulong qt_timestamp = timestamp * 1000;
QString characters = QString::fromUtf8([[nsevent characters] UTF8String]);
ulong timestamp = [nsevent timestamp] * 1000;
Qt::KeyboardModifiers modifiers = [self convertKeyModifiers:[nsevent modifierFlags]];
QChar ch([[nsevent charactersIgnoringModifiers] characterAtIndex:0]);
NSString *charactersIgnoringModifiers = [nsevent charactersIgnoringModifiers];
QChar ch([charactersIgnoringModifiers characterAtIndex:0]);
int keyCode = [self convertKeyCode:ch];
QString text;
if (eventType == QEvent::KeyPress) {
// ignore text for the U+F700-U+F8FF range. This is used by Cocoa when
// delivering function keys (e.g. arrow keys, backspace, F1-F35, etc.)
if ([charactersIgnoringModifiers length] == 1 && (ch.unicode() < 0xf700 || ch.unicode() > 0xf8ff))
text = QString::fromUtf8([[nsevent characters] UTF8String]);
if (!m_keyEventsAccepted && m_composingText.isEmpty())
m_keyEventsAccepted = QWindowSystemInterface::tryHandleSynchronousShortcutEvent(m_window, qt_timestamp, keyCode, modifiers, characters);
m_keyEventsAccepted = QWindowSystemInterface::tryHandleSynchronousShortcutEvent(m_window, timestamp, keyCode, modifiers, text);
QObject *fo = QGuiApplication::focusObject();
if (!m_keyEventsAccepted && fo) {
@ -593,9 +598,8 @@ static QTouchDevice *touchDevice = 0;
}
}
}
if (!m_keyEventsAccepted && m_composingText.isEmpty())
QWindowSystemInterface::handleKeyEvent(m_window, qt_timestamp, QEvent::Type(eventType), keyCode, modifiers, characters);
QWindowSystemInterface::handleKeyEvent(m_window, timestamp, QEvent::Type(eventType), keyCode, modifiers, text);
}
- (void)keyDown:(NSEvent *)nsevent