summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qioswindow.mm
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/ios/qioswindow.mm')
-rw-r--r--src/plugins/platforms/ios/qioswindow.mm184
1 files changed, 25 insertions, 159 deletions
diff --git a/src/plugins/platforms/ios/qioswindow.mm b/src/plugins/platforms/ios/qioswindow.mm
index 7a0ff055ec..7d5c507972 100644
--- a/src/plugins/platforms/ios/qioswindow.mm
+++ b/src/plugins/platforms/ios/qioswindow.mm
@@ -41,6 +41,7 @@
#include "qiosglobal.h"
#include "qioswindow.h"
+#include "quiview.h"
#include "qioscontext.h"
#include "qiosinputcontext.h"
#include "qiosscreen.h"
@@ -58,33 +59,19 @@
#include <QtDebug>
-@interface QUIView : UIView <UIKeyInput>
-{
-@public
- UITextAutocapitalizationType autocapitalizationType;
- UITextAutocorrectionType autocorrectionType;
- BOOL enablesReturnKeyAutomatically;
- UIKeyboardAppearance keyboardAppearance;
- UIKeyboardType keyboardType;
- UIReturnKeyType returnKeyType;
- BOOL secureTextEntry;
- QIOSWindow *m_qioswindow;
- QHash<UITouch *, QWindowSystemInterface::TouchPoint> m_activeTouches;
- int m_nextTouchId;
-}
-
-@property(nonatomic) UITextAutocapitalizationType autocapitalizationType;
-@property(nonatomic) UITextAutocorrectionType autocorrectionType;
-@property(nonatomic) BOOL enablesReturnKeyAutomatically;
-@property(nonatomic) UIKeyboardAppearance keyboardAppearance;
-@property(nonatomic) UIKeyboardType keyboardType;
-@property(nonatomic) UIReturnKeyType returnKeyType;
-@property(nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry;
-
-@end
+// Include category as an alternative to using -ObjC (Apple QA1490)
+#include "quiview_textinput.mm"
@implementation QUIView
+@synthesize autocapitalizationType;
+@synthesize autocorrectionType;
+@synthesize enablesReturnKeyAutomatically;
+@synthesize keyboardAppearance;
+@synthesize keyboardType;
+@synthesize returnKeyType;
+@synthesize secureTextEntry;
+
+ (Class)layerClass
{
return [CAEAGLLayer class];
@@ -112,6 +99,7 @@
self.hidden = YES;
self.multipleTouchEnabled = YES;
+ m_inSendEventToFocusObject = NO;
}
return self;
@@ -259,6 +247,14 @@
m_activeTouches[touch].id = m_nextTouchId++;
}
+ if (m_activeTouches.size() == 1) {
+ QPlatformWindow *topLevel = m_qioswindow;
+ while (QPlatformWindow *p = topLevel->parent())
+ topLevel = p;
+ if (topLevel->window() != QGuiApplication::focusWindow())
+ topLevel->requestActivateWindow();
+ }
+
[self updateTouchList:touches withState:Qt::TouchPointPressed];
[self sendTouchEventWithTimestamp:ulong(event.timestamp * 1000)];
}
@@ -271,14 +267,6 @@
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
- QWindow *window = m_qioswindow->window();
- if (window != QGuiApplication::focusWindow() && m_activeTouches.size() == 1) {
- // Activate the touched window if the last touch was released inside it:
- UITouch *touch = static_cast<UITouch *>([[touches allObjects] lastObject]);
- if (CGRectContainsPoint([self bounds], [touch locationInView:self]))
- m_qioswindow->requestActivateWindow();
- }
-
[self updateTouchList:touches withState:Qt::TouchPointReleased];
[self sendTouchEventWithTimestamp:ulong(event.timestamp * 1000)];
@@ -314,109 +302,6 @@
QWindowSystemInterface::flushWindowSystemEvents();
}
-@synthesize autocapitalizationType;
-@synthesize autocorrectionType;
-@synthesize enablesReturnKeyAutomatically;
-@synthesize keyboardAppearance;
-@synthesize keyboardType;
-@synthesize returnKeyType;
-@synthesize secureTextEntry;
-
-- (BOOL)canBecomeFirstResponder
-{
- return YES;
-}
-
-- (BOOL)becomeFirstResponder
-{
- // Note: QIOSInputContext controls our first responder status based on
- // whether or not the keyboard should be open or closed.
- [self updateTextInputTraits];
- return [super becomeFirstResponder];
-}
-
-- (BOOL)resignFirstResponder
-{
- // Resigning first responed status means that the virtual keyboard was closed, or
- // some other view became first responder. In either case we clear the focus object to
- // avoid blinking cursors in line edits etc:
- if (m_qioswindow)
- static_cast<QWindowPrivate *>(QObjectPrivate::get(m_qioswindow->window()))->clearFocusObject();
- return [super resignFirstResponder];
-}
-
-- (BOOL)hasText
-{
- return YES;
-}
-
-- (void)insertText:(NSString *)text
-{
- QString string = QString::fromUtf8([text UTF8String]);
- int key = 0;
- if ([text isEqualToString:@"\n"]) {
- key = (int)Qt::Key_Return;
- if (self.returnKeyType == UIReturnKeyDone)
- [self resignFirstResponder];
- }
-
- // Send key event to window system interface
- QWindowSystemInterface::handleKeyEvent(
- 0, QEvent::KeyPress, key, Qt::NoModifier, string, false, int(string.length()));
- QWindowSystemInterface::handleKeyEvent(
- 0, QEvent::KeyRelease, key, Qt::NoModifier, string, false, int(string.length()));
-}
-
-- (void)deleteBackward
-{
- // Send key event to window system interface
- QWindowSystemInterface::handleKeyEvent(
- 0, QEvent::KeyPress, (int)Qt::Key_Backspace, Qt::NoModifier);
- QWindowSystemInterface::handleKeyEvent(
- 0, QEvent::KeyRelease, (int)Qt::Key_Backspace, Qt::NoModifier);
-}
-
-- (void)updateTextInputTraits
-{
- // Ask the current focus object what kind of input it
- // expects, and configure the keyboard appropriately:
- QObject *focusObject = QGuiApplication::focusObject();
- if (!focusObject)
- return;
- QInputMethodQueryEvent queryEvent(Qt::ImEnabled | Qt::ImHints);
- if (!QCoreApplication::sendEvent(focusObject, &queryEvent))
- return;
- if (!queryEvent.value(Qt::ImEnabled).toBool())
- return;
-
- Qt::InputMethodHints hints = static_cast<Qt::InputMethodHints>(queryEvent.value(Qt::ImHints).toUInt());
-
- self.returnKeyType = (hints & Qt::ImhMultiLine) ? UIReturnKeyDefault : UIReturnKeyDone;
- self.secureTextEntry = BOOL(hints & Qt::ImhHiddenText);
- self.autocorrectionType = (hints & Qt::ImhNoPredictiveText) ?
- UITextAutocorrectionTypeNo : UITextAutocorrectionTypeDefault;
-
- if (hints & Qt::ImhUppercaseOnly)
- self.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
- else if (hints & Qt::ImhNoAutoUppercase)
- self.autocapitalizationType = UITextAutocapitalizationTypeNone;
- else
- self.autocapitalizationType = UITextAutocapitalizationTypeSentences;
-
- if (hints & Qt::ImhUrlCharactersOnly)
- self.keyboardType = UIKeyboardTypeURL;
- else if (hints & Qt::ImhEmailCharactersOnly)
- self.keyboardType = UIKeyboardTypeEmailAddress;
- else if (hints & Qt::ImhDigitsOnly)
- self.keyboardType = UIKeyboardTypeNumberPad;
- else if (hints & Qt::ImhFormattedNumbersOnly)
- self.keyboardType = UIKeyboardTypeDecimalPad;
- else if (hints & Qt::ImhDialableCharactersOnly)
- self.keyboardType = UIKeyboardTypeNumberPad;
- else
- self.keyboardType = UIKeyboardTypeDefault;
-}
-
@end
@implementation UIView (QIOS)
@@ -487,7 +372,7 @@ void QIOSWindow::setVisible(bool visible)
m_view.hidden = !visible;
[m_view setNeedsDisplay];
- if (!isQtApplication())
+ if (!isQtApplication() || !window()->isTopLevel())
return;
// Since iOS doesn't do window management the way a Qt application
@@ -503,18 +388,16 @@ void QIOSWindow::setVisible(bool visible)
if (visible) {
requestActivateWindow();
-
- if (window()->isTopLevel())
- static_cast<QIOSScreen *>(screen())->updateStatusBarVisibility();
-
+ static_cast<QIOSScreen *>(screen())->updateStatusBarVisibility();
} else {
// Activate top-most visible QWindow:
NSArray *subviews = m_view.viewController.view.subviews;
for (int i = int(subviews.count) - 1; i >= 0; --i) {
UIView *view = [subviews objectAtIndex:i];
if (!view.hidden) {
- if (QWindow *window = view.qwindow) {
- static_cast<QIOSWindow *>(window->handle())->requestActivateWindow();
+ QWindow *w = view.qwindow;
+ if (w && w->isTopLevel()) {
+ static_cast<QIOSWindow *>(w->handle())->requestActivateWindow();
break;
}
}
@@ -636,23 +519,6 @@ void QIOSWindow::setParent(const QPlatformWindow *parentWindow)
}
}
-QWindow *QIOSWindow::topLevelWindow() const
-{
- QWindow *window = this->window();
- while (window) {
- QWindow *parent = window->parent();
- if (!parent)
- parent = window->transientParent();
-
- if (!parent)
- break;
-
- window = parent;
- }
-
- return window;
-}
-
void QIOSWindow::requestActivateWindow()
{
// Note that several windows can be active at the same time if they exist in the same