22// Use of this source code is governed by a BSD-style license that can be
33// found in the LICENSE file.
44
5- #include " key_event_channel .h"
5+ #include " keyboard_channel .h"
66
77#include < chrono>
88#include < codecvt>
99#include < locale>
1010#include < string>
1111
12+ #include " flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
1213#include " flutter/shell/platform/common/json_message_codec.h"
1314#include " flutter/shell/platform/tizen/channels/key_mapping.h"
1415#include " flutter/shell/platform/tizen/logger.h"
@@ -17,8 +18,10 @@ namespace flutter {
1718
1819namespace {
1920
20- constexpr char kChannelName [] = " flutter/keyevent" ;
21+ constexpr char kKeyboardChannelName [] = " flutter/keyboard" ;
22+ constexpr char kKeyEventChannelName [] = " flutter/keyevent" ;
2123
24+ constexpr char kGetKeyboardStateMethod [] = " getKeyboardState" ;
2225constexpr char kKeyMapKey [] = " keymap" ;
2326constexpr char kKeyCodeKey [] = " keyCode" ;
2427constexpr char kScanCodeKey [] = " scanCode" ;
@@ -88,17 +91,28 @@ uint32_t GetFallbackScanCodeFromKey(const std::string& key) {
8891
8992} // namespace
9093
91- KeyEventChannel::KeyEventChannel (BinaryMessenger* messenger,
94+ KeyboardChannel::KeyboardChannel (BinaryMessenger* messenger,
9295 SendEventHandler send_event)
93- : channel_ (std::make_unique<BasicMessageChannel<rapidjson::Document >>(
96+ : keyboard_channel_ (std::make_unique<MethodChannel<EncodableValue >>(
9497 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+ }
98112
99- KeyEventChannel ::~KeyEventChannel () {}
113+ KeyboardChannel ::~KeyboardChannel () {}
100114
101- void KeyEventChannel ::SendKey (const char * key,
115+ void KeyboardChannel ::SendKey (const char * key,
102116 const char * string,
103117 const char * compose,
104118 uint32_t modifiers,
@@ -130,13 +144,13 @@ void KeyEventChannel::SendKey(const char* key,
130144 SendEmbedderEvent (key, string, compose, modifiers, scan_code, is_down,
131145 sequence_id);
132146 // 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
134148 // also be renamed and refactored then.
135149 SendChannelEvent (key, string, compose, modifiers, scan_code, is_down,
136150 sequence_id);
137151}
138152
139- void KeyEventChannel ::SendChannelEvent (const char * key,
153+ void KeyboardChannel ::SendChannelEvent (const char * key,
140154 const char * string,
141155 const char * compose,
142156 uint32_t modifiers,
@@ -174,7 +188,7 @@ void KeyEventChannel::SendChannelEvent(const char* key,
174188 } else {
175189 event.AddMember (kTypeKey , kKeyUp , allocator);
176190 }
177- channel_ ->Send (
191+ key_event_channel_ ->Send (
178192 event, [this , sequence_id](const uint8_t * reply, size_t reply_size) {
179193 if (reply != nullptr ) {
180194 std::unique_ptr<rapidjson::Document> decoded =
@@ -185,7 +199,7 @@ void KeyEventChannel::SendChannelEvent(const char* key,
185199 });
186200}
187201
188- void KeyEventChannel ::SendEmbedderEvent (const char * key,
202+ void KeyboardChannel ::SendEmbedderEvent (const char * key,
189203 const char * string,
190204 const char * compose,
191205 uint32_t modifiers,
@@ -262,7 +276,7 @@ void KeyEventChannel::SendEmbedderEvent(const char* key,
262276 }));
263277}
264278
265- void KeyEventChannel ::ResolvePendingEvent (uint64_t sequence_id, bool handled) {
279+ void KeyboardChannel ::ResolvePendingEvent (uint64_t sequence_id, bool handled) {
266280 auto iter = pending_events_.find (sequence_id);
267281 if (iter != pending_events_.end ()) {
268282 PendingEvent* event = iter->second .get ();
@@ -279,4 +293,22 @@ void KeyEventChannel::ResolvePendingEvent(uint64_t sequence_id, bool handled) {
279293 FT_ASSERT_NOT_REACHED ();
280294}
281295
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+
282314} // namespace flutter
0 commit comments