summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/ios')
-rw-r--r--src/plugins/platforms/ios/qioscontext.mm9
-rw-r--r--src/plugins/platforms/ios/qiosmenu.mm17
-rw-r--r--src/plugins/platforms/ios/qiostextresponder.mm61
3 files changed, 81 insertions, 6 deletions
diff --git a/src/plugins/platforms/ios/qioscontext.mm b/src/plugins/platforms/ios/qioscontext.mm
index fe0ca33c13..8bdb4bcdb3 100644
--- a/src/plugins/platforms/ios/qioscontext.mm
+++ b/src/plugins/platforms/ios/qioscontext.mm
@@ -45,12 +45,15 @@
QIOSContext::QIOSContext(QOpenGLContext *context)
: QPlatformOpenGLContext()
, m_sharedContext(static_cast<QIOSContext *>(context->shareHandle()))
+ , m_eaglContext(0)
, m_format(context->format())
{
m_format.setRenderableType(QSurfaceFormat::OpenGLES);
- m_eaglContext = [[EAGLContext alloc]
- initWithAPI:EAGLRenderingAPI(m_format.majorVersion())
- sharegroup:m_sharedContext ? [m_sharedContext->m_eaglContext sharegroup] : nil];
+
+ EAGLSharegroup *shareGroup = m_sharedContext ? [m_sharedContext->m_eaglContext sharegroup] : nil;
+ const int preferredVersion = m_format.majorVersion() == 1 ? kEAGLRenderingAPIOpenGLES1 : kEAGLRenderingAPIOpenGLES3;
+ for (int version = preferredVersion; !m_eaglContext && version >= m_format.majorVersion(); --version)
+ m_eaglContext = [[EAGLContext alloc] initWithAPI:EAGLRenderingAPI(version) sharegroup:shareGroup];
if (m_eaglContext != nil) {
EAGLContext *originalContext = [EAGLContext currentContext];
diff --git a/src/plugins/platforms/ios/qiosmenu.mm b/src/plugins/platforms/ios/qiosmenu.mm
index f68321fb3b..5f9346816a 100644
--- a/src/plugins/platforms/ios/qiosmenu.mm
+++ b/src/plugins/platforms/ios/qiosmenu.mm
@@ -62,11 +62,23 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_";
{
if (self = [super init]) {
[self setVisibleMenuItems:visibleMenuItems];
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(menuClosed)
+ name:UIMenuControllerDidHideMenuNotification object:nil];
}
return self;
}
+-(void)dealloc
+{
+ [[NSNotificationCenter defaultCenter]
+ removeObserver:self
+ name:UIMenuControllerDidHideMenuNotification object:nil];
+ [super dealloc];
+}
+
- (void)setVisibleMenuItems:(const QIOSMenuItemList &)visibleMenuItems
{
m_visibleMenuItems = visibleMenuItems;
@@ -86,6 +98,11 @@ static NSString *const kSelectorPrefix = @"_qtMenuItem_";
[[UIMenuController sharedMenuController] setMenuVisible:YES animated:NO];
}
+-(void)menuClosed
+{
+ QIOSMenu::currentMenu()->dismiss();
+}
+
- (id)targetForAction:(SEL)action withSender:(id)sender
{
Q_UNUSED(sender);
diff --git a/src/plugins/platforms/ios/qiostextresponder.mm b/src/plugins/platforms/ios/qiostextresponder.mm
index 9ca5e22b90..320b1cac61 100644
--- a/src/plugins/platforms/ios/qiostextresponder.mm
+++ b/src/plugins/platforms/ios/qiostextresponder.mm
@@ -318,7 +318,11 @@
// a regular responder transfer to another window. In the former case, iOS
// will set the new first-responder to our next-responder, and in the latter
// case we'll have an active responder candidate.
- if ([UIResponder currentFirstResponder] == [self nextResponder]) {
+ if (![UIResponder currentFirstResponder]) {
+ // No first responder set anymore, sync this with Qt by clearing the
+ // focus object.
+ m_inputContext->clearCurrentFocusObject();
+ } else if ([UIResponder currentFirstResponder] == [self nextResponder]) {
// We have resigned the keyboard, and transferred first responder back to the parent view
Q_ASSERT(!FirstResponderCandidate::currentCandidate());
if ([self currentImeState:Qt::ImEnabled].toBool()) {
@@ -364,6 +368,32 @@
[self sendKeyPressRelease:key modifiers:modifiers];
}
+- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
+{
+ bool isEditAction = (action == @selector(cut:)
+ || action == @selector(copy:)
+ || action == @selector(paste:)
+ || action == @selector(delete:)
+ || action == @selector(toggleBoldface:)
+ || action == @selector(toggleItalics:)
+ || action == @selector(toggleUnderline:)
+ || action == @selector(undo)
+ || action == @selector(redo));
+
+ bool isSelectAction = (action == @selector(select:)
+ || action == @selector(selectAll:)
+ || action == @selector(paste:)
+ || action == @selector(undo)
+ || action == @selector(redo));
+
+ const bool unknownAction = !isEditAction && !isSelectAction;
+ const bool hasSelection = ![self selectedTextRange].empty;
+
+ if (unknownAction)
+ return [super canPerformAction:action withSender:sender];
+ return (hasSelection && isEditAction) || (!hasSelection && isSelectAction);
+}
+
- (void)cut:(id)sender
{
Q_UNUSED(sender);
@@ -382,6 +412,13 @@
[self sendShortcut:QKeySequence::Paste];
}
+- (void)select:(id)sender
+{
+ Q_UNUSED(sender);
+ [self sendShortcut:QKeySequence::MoveToPreviousWord];
+ [self sendShortcut:QKeySequence::SelectNextWord];
+}
+
- (void)selectAll:(id)sender
{
Q_UNUSED(sender);
@@ -580,7 +617,8 @@
- (UITextPosition *)endOfDocument
{
- int endPosition = [self currentImeState:Qt::ImSurroundingText].toString().length();
+ QString surroundingText = [self currentImeState:Qt::ImSurroundingText].toString();
+ int endPosition = surroundingText.length() + m_markedText.length();
return [QUITextPosition positionWithIndex:endPosition];
}
@@ -611,9 +649,18 @@
- (NSString *)textInRange:(UITextRange *)range
{
+ QString text = [self currentImeState:Qt::ImSurroundingText].toString();
+ if (!m_markedText.isEmpty()) {
+ // [UITextInput textInRange] is sparsely documented, but it turns out that unconfirmed
+ // marked text should be seen as a part of the text document. This is different from
+ // ImSurroundingText, which excludes it.
+ int cursorPos = [self currentImeState:Qt::ImCursorPosition].toInt();
+ text = text.left(cursorPos) + m_markedText + text.mid(cursorPos);
+ }
+
int s = static_cast<QUITextPosition *>([range start]).index;
int e = static_cast<QUITextPosition *>([range end]).index;
- return [self currentImeState:Qt::ImSurroundingText].toString().mid(s, e - s).toNSString();
+ return text.mid(s, e - s).toNSString();
}
- (void)setMarkedText:(NSString *)markedText selectedRange:(NSRange)selectedRange
@@ -882,6 +929,14 @@
if ([text isEqualToString:@"\n"]) {
[self sendKeyPressRelease:Qt::Key_Return modifiers:Qt::NoModifier];
+ // An onEnter handler of a TextInput might move to the next input by calling
+ // nextInput.forceActiveFocus() which changes the focusObject.
+ // In that case we don't want to hide the VKB.
+ if (focusObject != QGuiApplication::focusObject()) {
+ qImDebug() << "focusObject already changed, not resigning first responder.";
+ return;
+ }
+
if (self.returnKeyType == UIReturnKeyDone || self.returnKeyType == UIReturnKeyGo
|| self.returnKeyType == UIReturnKeySend || self.returnKeyType == UIReturnKeySearch)
[self resignFirstResponder];