summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/ios/qiosinputcontext.h
blob: 370032a1f8a3fecde7987e0e85ef82e8765f46ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (C) 2020 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#ifndef QIOSINPUTCONTEXT_H
#define QIOSINPUTCONTEXT_H

#include <UIKit/UIKit.h>

#include <QtCore/qlocale.h>
#include <QtGui/qevent.h>
#include <QtGui/qtransform.h>
#include <qpa/qplatforminputcontext.h>

const char kImePlatformDataInputView[] = "inputView";
const char kImePlatformDataInputAccessoryView[] = "inputAccessoryView";
const char kImePlatformDataHideShortcutsBar[] = "hideShortcutsBar";
const char kImePlatformDataReturnKeyType[] = "returnKeyType";

@class QIOSLocaleListener;
@class QIOSKeyboardListener;
@class QIOSTextResponder;
@protocol KeyboardState;

QT_BEGIN_NAMESPACE

struct KeyboardState
{
    KeyboardState() :
        keyboardVisible(false), keyboardAnimating(false),
        animationDuration(0), animationCurve(UIViewAnimationCurve(-1))
        {}

    bool keyboardVisible;
    bool keyboardAnimating;
    QRectF keyboardRect;
    CGRect keyboardEndRect;
    NSTimeInterval animationDuration;
    UIViewAnimationCurve animationCurve;
};

struct ImeState
{
    ImeState() = default;
    Qt::InputMethodQueries update(Qt::InputMethodQueries properties);
    QInputMethodQueryEvent currentState = QInputMethodQueryEvent({});
    QObject *focusObject = nullptr;
};

class QIOSInputContext : public QPlatformInputContext
{
public:
    QIOSInputContext();
    ~QIOSInputContext();

    bool isValid() const override { return true; }

    void showInputPanel() override;
    void hideInputPanel() override;

    bool isInputPanelVisible() const override;
    bool isAnimating() const override;
    QRectF keyboardRect() const override;

    void update(Qt::InputMethodQueries) override;
    void reset() override;
    void commit() override;

    QLocale locale() const override;

    void clearCurrentFocusObject();

    void setFocusObject(QObject *object) override;
    void focusWindowChanged(QWindow *focusWindow);

    void scrollToCursor();
    void scroll(int y);

    void updateKeyboardState(NSNotification *notification = nullptr);

    const ImeState &imeState() { return m_imeState; }
    const KeyboardState &keyboardState() { return m_keyboardState; }

    bool inputMethodAccepted() const;

    static QIOSInputContext *instance();

private:
    UIView* scrollableRootView();

    QIOSLocaleListener *m_localeListener;
    QIOSKeyboardListener *m_keyboardHideGesture;
    QIOSTextResponder *m_textResponder;
    KeyboardState m_keyboardState;
    ImeState m_imeState;
};

QT_END_NAMESPACE

#endif