Skip to content

Commit 87e3e3b

Browse files
authored
[NUI] Support software keyboard input (#349)
Converts key event information from NUI to Ecore_IMF_Event and deliver it to Ecore_IMF_Context. In ecore_imf_context_filter_event, keys not used for software keyboard are sent to FlutterTizenView. related issue: #340 related pr : flutter-tizen/flutter-tizen#448
1 parent c82e17e commit 87e3e3b

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

shell/platform/tizen/flutter_tizen.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include "flutter/shell/platform/tizen/logger.h"
1515
#include "flutter/shell/platform/tizen/public/flutter_platform_view.h"
1616
#include "flutter/shell/platform/tizen/tizen_view.h"
17+
#ifdef NUI_SUPPORT
18+
#include "flutter/shell/platform/tizen/tizen_view_nui.h"
19+
#endif
1720
#include "flutter/shell/platform/tizen/tizen_window.h"
1821
#ifndef WEARABLE_PROFILE
1922
#include "flutter/shell/platform/tizen/tizen_window_ecore_wl2.h"
@@ -266,13 +269,30 @@ void FlutterDesktopViewOnPointerEvent(FlutterDesktopViewRef view,
266269
}
267270

268271
void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view,
272+
const char* device_name,
273+
uint32_t device_class,
274+
uint32_t device_subclass,
269275
const char* key,
270276
const char* string,
271277
uint32_t modifiers,
272278
uint32_t scan_code,
279+
size_t timestamp,
273280
bool is_down) {
281+
#ifdef NUI_SUPPORT
282+
auto* tizen_view = reinterpret_cast<flutter::TizenViewBase*>(
283+
ViewFromHandle(view)->tizen_view());
284+
285+
if (tizen_view->GetType() == flutter::TizenViewType::kView &&
286+
ViewFromHandle(view)->engine()->renderer()->type() ==
287+
FlutterDesktopRendererType::kEGL) {
288+
reinterpret_cast<flutter::TizenViewNui*>(tizen_view)
289+
->OnKey(device_name, device_class, device_subclass, key, string,
290+
nullptr, modifiers, scan_code, timestamp, is_down);
291+
}
292+
#else
274293
ViewFromHandle(view)->OnKey(key, string, nullptr, modifiers, scan_code,
275294
is_down);
295+
#endif
276296
}
277297

278298
void FlutterDesktopViewSetFocus(FlutterDesktopViewRef view, bool focused) {

shell/platform/tizen/public/flutter_tizen.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,14 @@ FLUTTER_EXPORT void FlutterDesktopViewOnPointerEvent(
210210
int32_t device_id);
211211

212212
FLUTTER_EXPORT void FlutterDesktopViewOnKeyEvent(FlutterDesktopViewRef view,
213+
const char* device_name,
214+
uint32_t device_class,
215+
uint32_t device_subclass,
213216
const char* key,
214217
const char* string,
215218
uint32_t modifiers,
216219
uint32_t scan_code,
220+
size_t timestamp,
217221
bool is_down);
218222

219223
FLUTTER_EXPORT void FlutterDesktopViewSetFocus(FlutterDesktopViewRef view,

shell/platform/tizen/tizen_input_method_context.cc

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ TizenInputMethodContext::TizenInputMethodContext(uintptr_t window_id) {
146146
TizenInputMethodContext::~TizenInputMethodContext() {
147147
UnregisterEventCallbacks();
148148

149+
#ifdef NUI_SUPPORT
150+
if (ecore_device_) {
151+
ecore_device_del(ecore_device_);
152+
}
153+
#endif
154+
149155
if (imf_context_) {
150156
ecore_imf_context_del(imf_context_);
151157
}
@@ -191,6 +197,51 @@ bool TizenInputMethodContext::HandleEvasEventKeyUp(Evas_Event_Key_Up* event) {
191197
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
192198
}
193199

200+
#ifdef NUI_SUPPORT
201+
bool TizenInputMethodContext::HandleNuiKeyEvent(const char* device_name,
202+
uint32_t device_class,
203+
uint32_t device_subclass,
204+
const char* key,
205+
const char* string,
206+
uint32_t modifiers,
207+
uint32_t scan_code,
208+
size_t timestamp,
209+
bool is_down) {
210+
Ecore_Event_Key event;
211+
event.keyname = event.key = key ? key : "";
212+
event.string = string ? string : "";
213+
event.modifiers = modifiers;
214+
event.keycode = scan_code;
215+
event.timestamp = timestamp;
216+
if (device_name) {
217+
if (!ecore_device_) {
218+
ecore_device_ = ecore_device_add();
219+
}
220+
221+
event.dev = ecore_device_;
222+
ecore_device_name_set(event.dev, device_name);
223+
ecore_device_class_set(event.dev,
224+
static_cast<Ecore_IMF_Device_Class>(device_class));
225+
ecore_device_subclass_set(
226+
event.dev, static_cast<Ecore_IMF_Device_Subclass>(device_subclass));
227+
}
228+
229+
if (is_down) {
230+
Ecore_IMF_Event_Key_Down imf_event =
231+
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Down>(&event);
232+
return ecore_imf_context_filter_event(
233+
imf_context_, ECORE_IMF_EVENT_KEY_DOWN,
234+
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
235+
} else {
236+
Ecore_IMF_Event_Key_Up imf_event =
237+
EcoreEventKeyToEcoreImfEvent<Ecore_IMF_Event_Key_Up>(&event);
238+
return ecore_imf_context_filter_event(
239+
imf_context_, ECORE_IMF_EVENT_KEY_UP,
240+
reinterpret_cast<Ecore_IMF_Event*>(&imf_event));
241+
}
242+
}
243+
#endif
244+
194245
InputPanelGeometry TizenInputMethodContext::GetInputPanelGeometry() {
195246
FT_ASSERT(imf_context_);
196247
InputPanelGeometry geometry;

shell/platform/tizen/tizen_input_method_context.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ class TizenInputMethodContext {
3535

3636
bool HandleEvasEventKeyUp(Evas_Event_Key_Up* event);
3737

38+
#ifdef NUI_SUPPORT
39+
bool HandleNuiKeyEvent(const char* device_name,
40+
uint32_t device_class,
41+
uint32_t device_subclass,
42+
const char* key,
43+
const char* string,
44+
uint32_t modifiers,
45+
uint32_t scan_code,
46+
size_t timestamp,
47+
bool is_down);
48+
#endif
49+
3850
InputPanelGeometry GetInputPanelGeometry();
3951

4052
void ResetInputMethodContext();
@@ -70,6 +82,9 @@ class TizenInputMethodContext {
7082
void SetContextOptions();
7183
void SetInputPanelOptions();
7284

85+
#ifdef NUI_SUPPORT
86+
Ecore_Device* ecore_device_ = nullptr;
87+
#endif
7388
Ecore_IMF_Context* imf_context_ = nullptr;
7489
OnCommit on_commit_;
7590
OnPreeditChanged on_preedit_changed_;

shell/platform/tizen/tizen_view_nui.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ void TizenViewNui::RequestRendering() {
7474
rendering_callback_->Trigger();
7575
}
7676

77+
void TizenViewNui::OnKey(const char* device_name,
78+
uint32_t device_class,
79+
uint32_t device_subclass,
80+
const char* key,
81+
const char* string,
82+
const char* compose,
83+
uint32_t modifiers,
84+
uint32_t scan_code,
85+
size_t timestamp,
86+
bool is_down) {
87+
bool handled = false;
88+
89+
if (input_method_context_->IsInputPanelShown()) {
90+
handled = input_method_context_->HandleNuiKeyEvent(
91+
device_name, device_class, device_subclass, key, string, modifiers,
92+
scan_code, timestamp, is_down);
93+
}
94+
95+
if (!handled) {
96+
view_delegate_->OnKey(key, string, compose, modifiers, scan_code, is_down);
97+
}
98+
}
99+
77100
void TizenViewNui::PrepareInputMethod() {
78101
input_method_context_ =
79102
std::make_unique<TizenInputMethodContext>(GetWindowId());

shell/platform/tizen/tizen_view_nui.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ class TizenViewNui : public TizenView {
4242

4343
void RequestRendering();
4444

45+
void OnKey(const char* device_name,
46+
uint32_t device_class,
47+
uint32_t device_subclass,
48+
const char* key,
49+
const char* string,
50+
const char* compose,
51+
uint32_t modifiers,
52+
uint32_t scan_code,
53+
size_t timestamp,
54+
bool is_down);
55+
4556
private:
4657
void RegisterEventHandlers();
4758

0 commit comments

Comments
 (0)