9 #include "flutter/fml/logging.h"
19 static constexpr
int kMaxPendingEvents = 1000;
22 static constexpr
char kChannelName[] =
"flutter/keyboard";
24 static constexpr
char kGetKeyboardStateMethod[] =
"getKeyboardState";
32 : last_sequence_id_(1),
41 channel_->SetMethodCallHandler(
44 HandleMethodCall(call, std::move(result));
48 void KeyboardKeyHandler::HandleMethodCall(
51 const std::string& method = method_call.
method_name();
52 if (method.compare(kGetKeyboardStateMethod) == 0) {
55 for (
const auto& pressed_key : pressed_state) {
56 EncodableValue physical_value(
static_cast<long long>(pressed_key.first));
57 EncodableValue logical_value(
static_cast<long long>(pressed_key.second));
58 value[physical_value] = logical_value;
60 result->Success(EncodableValue(value));
62 result->NotImplemented();
67 std::unique_ptr<KeyboardKeyHandlerDelegate> delegate) {
68 delegates_.push_back(std::move(delegate));
73 auto& key_embedder_handler = delegates_.front();
74 key_embedder_handler->SyncModifiersIfNeeded(modifiers_state);
79 auto& key_embedder_handler = delegates_.front();
80 return key_embedder_handler->GetPressedState();
90 std::unique_ptr<PendingEvent> incoming = std::make_unique<PendingEvent>();
92 uint64_t sequence_id = ++last_sequence_id_;
93 incoming->sequence_id = sequence_id;
94 incoming->unreplied = delegates_.size();
95 incoming->any_handled =
false;
96 incoming->callback = std::move(
callback);
98 if (pending_responds_.size() > kMaxPendingEvents) {
100 <<
"There are " << pending_responds_.size()
101 <<
" keyboard events that have not yet received a response from the "
102 <<
"framework. Are responses being sent?";
104 pending_responds_.push_back(std::move(incoming));
106 for (
const auto& delegate : delegates_) {
108 [sequence_id,
this](
bool handled) {
109 ResolvePendingEvent(sequence_id, handled);
120 void KeyboardKeyHandler::ResolvePendingEvent(uint64_t sequence_id,
123 for (
auto iter = pending_responds_.begin(); iter != pending_responds_.end();
125 if ((*iter)->sequence_id == sequence_id) {
126 PendingEvent&
event = **iter;
127 event.any_handled =
event.any_handled || handled;
128 event.unreplied -= 1;
129 FML_DCHECK(event.unreplied >= 0)
130 <<
"Pending events must have unreplied count > 0";
132 if (event.unreplied == 0) {
133 std::unique_ptr<PendingEvent> event_ptr = std::move(*iter);
134 pending_responds_.erase(iter);
135 event.callback(event.any_handled);
142 FML_LOG(FATAL) <<
"Could not find pending key event for sequence ID "