2
2
// Use of this source code is governed by a BSD-style license that can be
3
3
// found in the LICENSE file.
4
4
5
- #include " key_event_channel .h"
5
+ #include " keyboard_channel .h"
6
6
7
7
#include < chrono>
8
8
#include < codecvt>
9
9
#include < locale>
10
10
#include < string>
11
11
12
+ #include " flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
12
13
#include " flutter/shell/platform/common/json_message_codec.h"
13
14
#include " flutter/shell/platform/tizen/channels/key_mapping.h"
14
15
#include " flutter/shell/platform/tizen/logger.h"
@@ -17,8 +18,10 @@ namespace flutter {
17
18
18
19
namespace {
19
20
20
- constexpr char kChannelName [] = " flutter/keyevent" ;
21
+ constexpr char kKeyboardChannelName [] = " flutter/keyboard" ;
22
+ constexpr char kKeyEventChannelName [] = " flutter/keyevent" ;
21
23
24
+ constexpr char kGetKeyboardStateMethod [] = " getKeyboardState" ;
22
25
constexpr char kKeyMapKey [] = " keymap" ;
23
26
constexpr char kKeyCodeKey [] = " keyCode" ;
24
27
constexpr char kScanCodeKey [] = " scanCode" ;
@@ -88,17 +91,28 @@ uint32_t GetFallbackScanCodeFromKey(const std::string& key) {
88
91
89
92
} // namespace
90
93
91
- KeyEventChannel::KeyEventChannel (BinaryMessenger* messenger,
94
+ KeyboardChannel::KeyboardChannel (BinaryMessenger* messenger,
92
95
SendEventHandler send_event)
93
- : channel_ (std::make_unique<BasicMessageChannel<rapidjson::Document >>(
96
+ : keyboard_channel_ (std::make_unique<MethodChannel<EncodableValue >>(
94
97
messenger,
95
- kChannelName ,
96
- &JsonMessageCodec::GetInstance ())),
97
- send_event_(send_event) {}
98
+ kKeyboardChannelName ,
99
+ &StandardMethodCodec::GetInstance ())),
100
+ key_event_channel_(
101
+ std::make_unique<BasicMessageChannel<rapidjson::Document>>(
102
+ messenger,
103
+ kKeyEventChannelName ,
104
+ &JsonMessageCodec::GetInstance ())),
105
+ send_event_(send_event) {
106
+ keyboard_channel_->SetMethodCallHandler (
107
+ [this ](const MethodCall<EncodableValue>& call,
108
+ std::unique_ptr<MethodResult<EncodableValue>> result) {
109
+ HandleMethodCall (call, std::move (result));
110
+ });
111
+ }
98
112
99
- KeyEventChannel ::~KeyEventChannel () {}
113
+ KeyboardChannel ::~KeyboardChannel () {}
100
114
101
- void KeyEventChannel ::SendKey (const char * key,
115
+ void KeyboardChannel ::SendKey (const char * key,
102
116
const char * string,
103
117
const char * compose,
104
118
uint32_t modifiers,
@@ -130,13 +144,13 @@ void KeyEventChannel::SendKey(const char* key,
130
144
SendEmbedderEvent (key, string, compose, modifiers, scan_code, is_down,
131
145
sequence_id);
132
146
// The channel-based API (RawKeyEvent) is deprecated and |SendChannelEvent|
133
- // will be removed in the future. This class (KeyEventChannel ) itself will
147
+ // will be removed in the future. This class (KeyboardChannel ) itself will
134
148
// also be renamed and refactored then.
135
149
SendChannelEvent (key, string, compose, modifiers, scan_code, is_down,
136
150
sequence_id);
137
151
}
138
152
139
- void KeyEventChannel ::SendChannelEvent (const char * key,
153
+ void KeyboardChannel ::SendChannelEvent (const char * key,
140
154
const char * string,
141
155
const char * compose,
142
156
uint32_t modifiers,
@@ -174,7 +188,7 @@ void KeyEventChannel::SendChannelEvent(const char* key,
174
188
} else {
175
189
event.AddMember (kTypeKey , kKeyUp , allocator);
176
190
}
177
- channel_ ->Send (
191
+ key_event_channel_ ->Send (
178
192
event, [this , sequence_id](const uint8_t * reply, size_t reply_size) {
179
193
if (reply != nullptr ) {
180
194
std::unique_ptr<rapidjson::Document> decoded =
@@ -185,7 +199,7 @@ void KeyEventChannel::SendChannelEvent(const char* key,
185
199
});
186
200
}
187
201
188
- void KeyEventChannel ::SendEmbedderEvent (const char * key,
202
+ void KeyboardChannel ::SendEmbedderEvent (const char * key,
189
203
const char * string,
190
204
const char * compose,
191
205
uint32_t modifiers,
@@ -262,7 +276,7 @@ void KeyEventChannel::SendEmbedderEvent(const char* key,
262
276
}));
263
277
}
264
278
265
- void KeyEventChannel ::ResolvePendingEvent (uint64_t sequence_id, bool handled) {
279
+ void KeyboardChannel ::ResolvePendingEvent (uint64_t sequence_id, bool handled) {
266
280
auto iter = pending_events_.find (sequence_id);
267
281
if (iter != pending_events_.end ()) {
268
282
PendingEvent* event = iter->second .get ();
@@ -279,4 +293,22 @@ void KeyEventChannel::ResolvePendingEvent(uint64_t sequence_id, bool handled) {
279
293
FT_ASSERT_NOT_REACHED ();
280
294
}
281
295
296
+ void KeyboardChannel::HandleMethodCall (
297
+ const MethodCall<EncodableValue>& method_call,
298
+ std::unique_ptr<MethodResult<EncodableValue>> result) {
299
+ const std::string& method_name = method_call.method_name ();
300
+ if (method_name == kGetKeyboardStateMethod ) {
301
+ EncodableMap map;
302
+ for (const auto & key : pressing_records_) {
303
+ EncodableValue physical_value (static_cast <int64_t >(key.first ));
304
+ EncodableValue logical_value (static_cast <int64_t >(key.second ));
305
+ map[physical_value] = logical_value;
306
+ }
307
+
308
+ result->Success (EncodableValue (map));
309
+ } else {
310
+ result->NotImplemented ();
311
+ }
312
+ }
313
+
282
314
} // namespace flutter
0 commit comments