summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qnsview.mm
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2017-08-29 09:56:36 +0200
committerEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>2017-09-04 13:51:19 +0000
commit52bda430af2749da1a0467b71d9cca5208f22402 (patch)
treedaa30b51a46f32cb3732b14ffe6e3cf321b1cf8b /src/plugins/platforms/cocoa/qnsview.mm
parentf9fea20c10ca7864cfa551fce23124d358c11b3a (diff)
macOS: Reset composition when focus object changes inside window
When the focus object inside a window changes and we are currently composing text, we have to cancel composition to avoid getting into an inconsistent state. This is what already happens if you switch to a different top level window. Note: Because we limit the user's ability to change focus inside a window when composing text, this would only happen under certain circumstances, such as creating a new MDI window with an editor while still composing text in a previous one. [ChangeLog][macOS] Switching focus objects inside a top level window while composing text using dead keys or input method events would leave the application in an inconsistent state. The composition now automatically cancels when the focus object changes. Task-number: QTBUG-59222 Change-Id: I06792a7db1441dcc5c87e4bf0861b422a25f7f7c Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/plugins/platforms/cocoa/qnsview.mm')
-rw-r--r--src/plugins/platforms/cocoa/qnsview.mm22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm
index a40bdfd314..ba5c0ea25d 100644
--- a/src/plugins/platforms/cocoa/qnsview.mm
+++ b/src/plugins/platforms/cocoa/qnsview.mm
@@ -1712,6 +1712,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
}
m_composingText.clear();
+ m_composingFocusObject = nullptr;
}
- (void) setMarkedText:(id)aString selectedRange:(NSRange)selectedRange replacementRange:(NSRange)replacementRange
@@ -1766,6 +1767,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()) {
@@ -1778,6 +1780,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()) {
@@ -1793,6 +1814,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
}
}
m_composingText.clear();
+ m_composingFocusObject = nullptr;
}
- (BOOL) hasMarkedText