diff options
author | Liang Qi <liang.qi@qt.io> | 2017-09-06 17:41:06 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2017-09-06 17:57:12 +0000 |
commit | 71ec67a0fd8aa8d9caab743647c2fdd4385c3e19 (patch) | |
tree | 25f541805067ffaf0d1a6365c19aac7eaf295551 /src/plugins/platforms/cocoa | |
parent | 03bcf389c0b525919b82a64ab5290189f2994846 (diff) | |
parent | 19dd2ca93b8b95a5e2792b29ed62ea23800fb53e (diff) |
Merge "Merge remote-tracking branch 'origin/5.9' into 5.10" into refs/staging/5.10
Diffstat (limited to 'src/plugins/platforms/cocoa')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoainputcontext.mm | 17 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.h | 2 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qnsview.mm | 22 |
3 files changed, 40 insertions, 1 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoainputcontext.mm b/src/plugins/platforms/cocoa/qcocoainputcontext.mm index 9e3d747cd7..9221099a57 100644 --- a/src/plugins/platforms/cocoa/qcocoainputcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoainputcontext.mm @@ -124,7 +124,22 @@ void QCocoaInputContext::connectSignals() void QCocoaInputContext::focusObjectChanged(QObject *focusObject) { Q_UNUSED(focusObject); - mWindow = QGuiApplication::focusWindow(); + if (mWindow == QGuiApplication::focusWindow()) { + if (!mWindow) + return; + + QCocoaWindow *window = static_cast<QCocoaWindow *>(mWindow->handle()); + QNSView *view = qnsview_cast(window->view()); + if (!view) + return; + + if (NSTextInputContext *ctxt = [NSTextInputContext currentInputContext]) { + [ctxt discardMarkedText]; + [view cancelComposingText]; + } + } else { + mWindow = QGuiApplication::focusWindow(); + } } void QCocoaInputContext::updateLocale() diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index a031853422..f8903725a6 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -63,6 +63,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); Qt::MouseButtons m_acceptedMouseDowns; Qt::MouseButtons m_frameStrutButtons; QString m_composingText; + QPointer<QObject> m_composingFocusObject; bool m_sendKeyEvent; QStringList *currentCustomDragTypes; bool m_dontOverrideCtrlLMB; @@ -93,6 +94,7 @@ Q_FORWARD_DECLARE_OBJC_CLASS(QT_MANGLE_NAMESPACE(QNSViewMouseMoveHelper)); - (void)textInputContextKeyboardSelectionDidChangeNotification : (NSNotification *) textInputContextKeyboardSelectionDidChangeNotification; - (void)viewDidHide; - (void)removeFromSuperview; +- (void)cancelComposingText; - (BOOL)isFlipped; - (BOOL)acceptsFirstResponder; diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index 16207d8de8..011bbd9d08 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -1544,6 +1544,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) } m_composingText.clear(); + m_composingFocusObject = nullptr; } - (void) setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange @@ -1598,6 +1599,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) m_composingText = preeditString; if (QObject *fo = m_platformWindow->window()->focusObject()) { + m_composingFocusObject = fo; QInputMethodQueryEvent queryEvent(Qt::ImEnabled); if (QCoreApplication::sendEvent(fo, &queryEvent)) { if (queryEvent.value(Qt::ImEnabled).toBool()) { @@ -1610,6 +1612,25 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) } } +- (void)cancelComposingText +{ + if (m_composingText.isEmpty()) + return; + + if (m_composingFocusObject) { + QInputMethodQueryEvent queryEvent(Qt::ImEnabled); + if (QCoreApplication::sendEvent(m_composingFocusObject, &queryEvent)) { + if (queryEvent.value(Qt::ImEnabled).toBool()) { + QInputMethodEvent e; + QCoreApplication::sendEvent(m_composingFocusObject, &e); + } + } + } + + m_composingText.clear(); + m_composingFocusObject = nullptr; +} + - (void) unmarkText { if (!m_composingText.isEmpty()) { @@ -1625,6 +1646,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent) } } m_composingText.clear(); + m_composingFocusObject = nullptr; } - (BOOL) hasMarkedText |