Skip to content

Commit a117967

Browse files
bbrto21swift-kim
authored andcommitted
Remove navigation key handling (#299)
* Navigation key event should be handled by the flutter framework. * Update related comments. * Fix incorrect type usage. Signed-off-by: Boram Bae <[email protected]>
1 parent 568dad3 commit a117967

File tree

6 files changed

+33
-41
lines changed

6 files changed

+33
-41
lines changed

shell/platform/tizen/channels/key_event_channel.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ uint64_t GetLogicalKey(const char* key) {
6262
return ApplyPlaneToId(0, kTizenPlane);
6363
}
6464

65+
uint32_t GetFallbackScanCodeFromKey(const std::string& key) {
66+
// Some of scan codes are 0 when key events occur from the software
67+
// keyboard, and key_event_channel cannot handle the key events.
68+
// To avoid this, use a valid scan code.
69+
70+
// The following keys can be emitted from the software keyboard and have a
71+
// scan code with 0 value.
72+
const std::map<std::string, uint32_t> kKeyToScanCode = {
73+
{"BackSpace", 0x00000016}, {"Up", 0x0000006f}, {"Left", 0x00000071},
74+
{"Right", 0x00000072}, {"Down", 0x00000074},
75+
};
76+
77+
auto iter = kKeyToScanCode.find(key);
78+
if (iter != kKeyToScanCode.end()) {
79+
return iter->second;
80+
}
81+
return 0;
82+
}
83+
6584
} // namespace
6685

6786
KeyEventChannel::KeyEventChannel(BinaryMessenger* messenger,
@@ -99,6 +118,10 @@ void KeyEventChannel::SendKey(const char* key,
99118
}
100119
pending_events_[sequence_id] = std::make_unique<PendingEvent>(pending);
101120

121+
if (scan_code == 0) {
122+
scan_code = GetFallbackScanCodeFromKey(key);
123+
}
124+
102125
SendEmbedderEvent(key, string, compose, modifiers, scan_code, is_down,
103126
sequence_id);
104127
// The channel-based API (RawKeyEvent) is deprecated and |SendChannelEvent|

shell/platform/tizen/channels/text_input_channel.cc

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -303,43 +303,11 @@ void TextInputChannel::SendStateUpdate() {
303303
bool TextInputChannel::HandleKey(const char* key,
304304
const char* string,
305305
uint32_t modifires) {
306-
bool shift = modifires & ECORE_SHIFT;
307306
bool needs_update = false;
308307
std::string key_str = key;
309308

310-
if (key_str == "Left") {
311-
if (shift) {
312-
TextRange selection = active_model_->selection();
313-
needs_update = active_model_->SetSelection(
314-
TextRange(selection.base(), selection.extent() - 1));
315-
} else {
316-
needs_update = active_model_->MoveCursorBack();
317-
}
318-
} else if (key_str == "Right") {
319-
if (shift) {
320-
TextRange selection = active_model_->selection();
321-
needs_update = active_model_->SetSelection(
322-
TextRange(selection.base(), selection.extent() + 1));
323-
} else {
324-
needs_update = active_model_->MoveCursorForward();
325-
}
326-
} else if (key_str == "End") {
327-
if (shift) {
328-
needs_update = active_model_->SelectToEnd();
329-
} else {
330-
needs_update = active_model_->MoveCursorToEnd();
331-
}
332-
} else if (key_str == "Home") {
333-
if (shift) {
334-
needs_update = active_model_->SelectToBeginning();
335-
} else {
336-
needs_update = active_model_->MoveCursorToBeginning();
337-
}
338-
} else if (key_str == "BackSpace") {
339-
needs_update = active_model_->Backspace();
340-
} else if (key_str == "Delete") {
341-
needs_update = active_model_->Delete();
342-
} else if (string && strlen(string) == 1 && IsAsciiPrintableKey(string[0])) {
309+
if (string && strlen(string) == 1 && IsAsciiPrintableKey(string[0])) {
310+
// This is a fallback for printable keys not handled by IMF.
343311
active_model_->AddCodePoint(string[0]);
344312
needs_update = true;
345313
} else if (key_str == "Return") {

shell/platform/tizen/tizen_input_method_context.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,14 @@ void TizenInputMethodContext::SetInputPanelOptions() {
347347
}
348348

349349
bool TizenInputMethodContext::ShouldIgnoreKey(std::string key, bool is_ime) {
350-
// The keys below should be handled in the text_input_channel.
350+
// The below keys should be handled by the flutter framework.
351351
if (is_ime && (key == "Left" || key == "Right" || key == "Up" ||
352352
key == "Down" || key == "End" || key == "Home" ||
353353
key == "BackSpace" || key == "Delete")) {
354354
return true;
355355
}
356356
#ifdef TV_PROFILE
357+
// The Select key should be handled in the TextInputChannel.
357358
if (is_ime && key == "Select") {
358359
return true;
359360
}

shell/platform/tizen/tizen_view_elementary.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ void TizenViewElementary::RegisterEventHandlers() {
215215
if (self->view_) {
216216
if (self->event_layer_ == object) {
217217
auto* key_event = reinterpret_cast<Evas_Event_Key_Down*>(event_info);
218-
int handled = false;
218+
bool handled = false;
219219
key_event->event_flags =
220220
Evas_Event_Flags(key_event->event_flags | EVAS_EVENT_FLAG_ON_HOLD);
221221
if (self->input_method_context_->IsInputPanelShown()) {
@@ -241,7 +241,7 @@ void TizenViewElementary::RegisterEventHandlers() {
241241
if (self->view_) {
242242
if (self->event_layer_ == object) {
243243
auto* key_event = reinterpret_cast<Evas_Event_Key_Up*>(event_info);
244-
int handled = false;
244+
bool handled = false;
245245
key_event->event_flags = Evas_Event_Flags(key_event->event_flags |
246246
EVAS_EVENT_FLAG_ON_HOLD);
247247
if (self->input_method_context_->IsInputPanelShown()) {

shell/platform/tizen/tizen_window_ecore_wl2.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ void TizenWindowEcoreWl2::RegisterEventHandlers() {
313313
if (self->view_) {
314314
auto* key_event = reinterpret_cast<Ecore_Event_Key*>(event);
315315
if (key_event->window == self->GetWindowId()) {
316-
int handled = false;
316+
bool handled = false;
317317
if (self->input_method_context_->IsInputPanelShown()) {
318318
handled = self->input_method_context_->HandleEcoreEventKey(
319319
key_event, true);
@@ -337,7 +337,7 @@ void TizenWindowEcoreWl2::RegisterEventHandlers() {
337337
if (self->view_) {
338338
auto* key_event = reinterpret_cast<Ecore_Event_Key*>(event);
339339
if (key_event->window == self->GetWindowId()) {
340-
int handled = false;
340+
bool handled = false;
341341
if (self->input_method_context_->IsInputPanelShown()) {
342342
handled = self->input_method_context_->HandleEcoreEventKey(
343343
key_event, false);

shell/platform/tizen/tizen_window_elementary.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ void TizenWindowElementary::RegisterEventHandlers() {
238238
if (self->view_) {
239239
if (self->elm_win_ == object) {
240240
auto* key_event = reinterpret_cast<Evas_Event_Key_Down*>(event_info);
241-
int handled = false;
241+
bool handled = false;
242242
if (self->input_method_context_->IsInputPanelShown()) {
243243
handled =
244244
self->input_method_context_->HandleEvasEventKeyDown(key_event);
@@ -262,7 +262,7 @@ void TizenWindowElementary::RegisterEventHandlers() {
262262
if (self->view_) {
263263
if (self->elm_win_ == object) {
264264
auto* key_event = reinterpret_cast<Evas_Event_Key_Up*>(event_info);
265-
int handled = false;
265+
bool handled = false;
266266
if (self->input_method_context_->IsInputPanelShown()) {
267267
handled =
268268
self->input_method_context_->HandleEvasEventKeyUp(key_event);

0 commit comments

Comments
 (0)