Skip to content

Commit 6f94b9c

Browse files
authored
Integrate keyboard channel (#49)
1 parent acf40d2 commit 6f94b9c

File tree

6 files changed

+69
-29
lines changed

6 files changed

+69
-29
lines changed

flutter/shell/platform/tizen/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ template("embedder") {
8484
"channels/app_control_channel.cc",
8585
"channels/feedback_manager.cc",
8686
"channels/input_device_channel.cc",
87-
"channels/key_event_channel.cc",
8887
"channels/key_mapping.cc",
88+
"channels/keyboard_channel.cc",
8989
"channels/lifecycle_channel.cc",
9090
"channels/mouse_cursor_channel.cc",
9191
"channels/navigation_channel.cc",

flutter/shell/platform/tizen/channels/key_event_channel.cc renamed to flutter/shell/platform/tizen/channels/keyboard_channel.cc

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
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

1819
namespace {
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";
2225
constexpr char kKeyMapKey[] = "keymap";
2326
constexpr char kKeyCodeKey[] = "keyCode";
2427
constexpr 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

flutter/shell/platform/tizen/channels/key_event_channel.h renamed to flutter/shell/platform/tizen/channels/keyboard_channel.h

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,32 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
#ifndef EMBEDDER_KEY_EVENT_CHANNEL_H_
6-
#define EMBEDDER_KEY_EVENT_CHANNEL_H_
5+
#ifndef EMBEDDER_KEYBOARD_CHANNEL_H_
6+
#define EMBEDDER_KEYBOARD_CHANNEL_H_
77

88
#include <functional>
99
#include <map>
1010
#include <memory>
1111

1212
#include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h"
1313
#include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
14+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/encodable_value.h"
15+
#include "flutter/shell/platform/common/client_wrapper/include/flutter/method_channel.h"
1416
#include "flutter/shell/platform/embedder/embedder.h"
17+
1518
#include "rapidjson/document.h"
1619

1720
namespace flutter {
1821

19-
class KeyEventChannel {
22+
class KeyboardChannel {
2023
public:
2124
using SendEventHandler = std::function<void(const FlutterKeyEvent& event,
2225
FlutterKeyEventCallback callback,
2326
void* user_data)>;
2427

25-
explicit KeyEventChannel(BinaryMessenger* messenger,
28+
explicit KeyboardChannel(BinaryMessenger* messenger,
2629
SendEventHandler send_event);
27-
virtual ~KeyEventChannel();
30+
virtual ~KeyboardChannel();
2831

2932
void SendKey(const char* key,
3033
const char* string,
@@ -35,7 +38,8 @@ class KeyEventChannel {
3538
std::function<void(bool)> callback);
3639

3740
private:
38-
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_;
41+
std::unique_ptr<flutter::MethodChannel<EncodableValue>> keyboard_channel_;
42+
std::unique_ptr<BasicMessageChannel<rapidjson::Document>> key_event_channel_;
3943
SendEventHandler send_event_;
4044

4145
struct PendingEvent {
@@ -76,8 +80,12 @@ class KeyEventChannel {
7680
uint64_t sequence_id);
7781

7882
void ResolvePendingEvent(uint64_t sequence_id, bool handled);
83+
84+
void HandleMethodCall(
85+
const flutter::MethodCall<EncodableValue>& method_call,
86+
std::unique_ptr<flutter::MethodResult<EncodableValue>> result);
7987
};
8088

8189
} // namespace flutter
8290

83-
#endif // EMBEDDER_KEY_EVENT_CHANNEL_H_
91+
#endif // EMBEDDER_KEYBOARD_CHANNEL_H_

flutter/shell/platform/tizen/flutter_tizen_engine.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ bool FlutterTizenEngine::RunEngine() {
247247

248248
if (IsHeaded()) {
249249
texture_registrar_ = std::make_unique<FlutterTizenTextureRegistrar>(this);
250-
key_event_channel_ = std::make_unique<KeyEventChannel>(
250+
keyboard_channel_ = std::make_unique<KeyboardChannel>(
251251
internal_plugin_registrar_->messenger(),
252252
[this](const FlutterKeyEvent& event, FlutterKeyEventCallback callback,
253253
void* user_data) { SendKeyEvent(event, callback, user_data); });

flutter/shell/platform/tizen/flutter_tizen_engine.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "flutter/shell/platform/tizen/accessibility_settings.h"
1818
#include "flutter/shell/platform/tizen/channels/accessibility_channel.h"
1919
#include "flutter/shell/platform/tizen/channels/app_control_channel.h"
20-
#include "flutter/shell/platform/tizen/channels/key_event_channel.h"
20+
#include "flutter/shell/platform/tizen/channels/keyboard_channel.h"
2121
#include "flutter/shell/platform/tizen/channels/lifecycle_channel.h"
2222
#include "flutter/shell/platform/tizen/channels/navigation_channel.h"
2323
#include "flutter/shell/platform/tizen/channels/platform_view_channel.h"
@@ -101,7 +101,7 @@ class FlutterTizenEngine {
101101
return app_control_channel_.get();
102102
}
103103

104-
KeyEventChannel* key_event_channel() { return key_event_channel_.get(); }
104+
KeyboardChannel* keyboard_channel() { return keyboard_channel_.get(); }
105105

106106
LifecycleChannel* lifecycle_channel() { return lifecycle_channel_.get(); }
107107

@@ -251,8 +251,8 @@ class FlutterTizenEngine {
251251
// A plugin that implements the Tizen app_control channel.
252252
std::unique_ptr<AppControlChannel> app_control_channel_;
253253

254-
// A plugin that implements the Flutter keyevent channel.
255-
std::unique_ptr<KeyEventChannel> key_event_channel_;
254+
// A plugin that implements the Flutter keyboard channel.
255+
std::unique_ptr<KeyboardChannel> keyboard_channel_;
256256

257257
// A plugin that implements the Flutter lifecycle channel.
258258
std::unique_ptr<LifecycleChannel> lifecycle_channel_;

flutter/shell/platform/tizen/flutter_tizen_view.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,8 @@ void FlutterTizenView::OnKey(const char* key,
351351
}
352352
}
353353

354-
if (engine_->key_event_channel()) {
355-
engine_->key_event_channel()->SendKey(
354+
if (engine_->keyboard_channel()) {
355+
engine_->keyboard_channel()->SendKey(
356356
key, string, compose, modifiers, scan_code, is_down,
357357
[engine = engine_.get(), symbol = std::string(key),
358358
is_down](bool handled) {

0 commit comments

Comments
 (0)