forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputMethodFilter.h
More file actions
130 lines (105 loc) · 3.68 KB
/
InputMethodFilter.h
File metadata and controls
130 lines (105 loc) · 3.68 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* Copyright (C) 2012, 2014, 2019 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include "InputMethodState.h"
#include <WebCore/CompositionUnderline.h>
#include <WebCore/IntPoint.h>
#include <wtf/Noncopyable.h>
#include <wtf/Vector.h>
#include <wtf/glib/GRefPtr.h>
typedef struct _WebKitInputMethodContext WebKitInputMethodContext;
#if PLATFORM(GTK)
#if USE(GTK4)
typedef struct _GdkEvent GdkEvent;
#else
typedef union _GdkEvent GdkEvent;
#endif
#elif PLATFORM(WPE)
struct wpe_input_keyboard_event;
#endif
namespace WebCore {
class IntRect;
}
namespace WebKit {
class InputMethodFilter {
WTF_MAKE_NONCOPYABLE(InputMethodFilter);
public:
InputMethodFilter() = default;
~InputMethodFilter();
void setContext(WebKitInputMethodContext*);
WebKitInputMethodContext* context() const { return m_context.get(); }
void setState(std::optional<InputMethodState>&&);
#if PLATFORM(GTK)
using PlatformEventKey = GdkEvent;
#elif PLATFORM(WPE)
using PlatformEventKey = struct wpe_input_keyboard_event;
#endif
struct FilterResult {
bool handled { false };
String keyText;
};
FilterResult filterKeyEvent(PlatformEventKey*);
#if PLATFORM(GTK)
FilterResult filterKeyEvent(unsigned type, unsigned keyval, unsigned keycode, unsigned modifiers);
#endif
void notifyFocusedIn();
void notifyFocusedOut();
void notifyMouseButtonPress();
void notifyCursorRect(const WebCore::IntRect&);
void notifySurrounding(const String&, uint64_t, uint64_t);
void cancelComposition();
private:
static void preeditStartedCallback(InputMethodFilter*);
static void preeditChangedCallback(InputMethodFilter*);
static void preeditFinishedCallback(InputMethodFilter*);
static void committedCallback(InputMethodFilter*, const char*);
static void deleteSurroundingCallback(InputMethodFilter*, int offset, unsigned characterCount);
void preeditStarted();
void preeditChanged();
void preeditFinished();
void committed(const char*);
void deleteSurrounding(int offset, unsigned characterCount);
bool isEnabled() const { return !!m_state; }
bool isViewFocused() const;
void notifyContentType();
WebCore::IntRect platformTransformCursorRectToViewCoordinates(const WebCore::IntRect&);
bool platformEventKeyIsKeyPress(PlatformEventKey*) const;
std::optional<InputMethodState> m_state;
GRefPtr<WebKitInputMethodContext> m_context;
struct {
String text;
Vector<WebCore::CompositionUnderline> underlines;
unsigned cursorOffset;
} m_preedit;
struct {
bool isActive { false };
bool preeditChanged { false };
#if PLATFORM(GTK) && USE(GTK4)
bool isFakeKeyEventForTesting { false };
#endif
} m_filteringContext;
String m_compositionResult;
WebCore::IntPoint m_cursorLocation;
struct {
String text;
uint64_t cursorPosition;
uint64_t selectionPosition;
} m_surrounding;
};
} // namespace WebKit