Skip to content

Commit

Permalink
Enable IMF on Webview (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
seungsoo47 committed Jan 14, 2021
1 parent 0076f80 commit 2fcca1d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 6 deletions.
16 changes: 16 additions & 0 deletions packages/webview_flutter/example/tizen/shared/res/input.html
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
</head>

<body>
<input id="ip1" type="text" ></input>
<button onclick="a()">Click</button>
<input id="ip2" type="text" ></input>
</body>
<script>
function a() {
console.log("Hello: " + document.getElementById("ip1").value);
}
</script>
</html>
11 changes: 5 additions & 6 deletions packages/webview_flutter/lib/webview_flutter_tizen.dart
Expand Up @@ -78,12 +78,10 @@ class TizenViewController extends PlatformViewController {

int _textureId;

@override
int get textureId => _textureId;

Size _size;

@override
Future<void> setSize(Size size) async {
assert(_state != _TizenViewState.disposed,
'trying to size a disposed Tizen View. View id: $viewId');
Expand All @@ -103,7 +101,6 @@ class TizenViewController extends PlatformViewController {
});
}

@override
Future<void> _sendCreateMessage() async {
assert(!_size.isEmpty,
'trying to create $TizenViewController without setting a valid size.');
Expand All @@ -128,7 +125,6 @@ class TizenViewController extends PlatformViewController {
await SystemChannels.platform_views.invokeMethod<int>('create', args);
}

@override
Future<void> _sendDisposeMessage() {
return SystemChannels.platform_views
.invokeMethod<void>('dispose', <String, dynamic>{
Expand Down Expand Up @@ -205,8 +201,8 @@ class TizenViewController extends PlatformViewController {
}
await SystemChannels.platform_views
.invokeMethod<dynamic>('touch', <String, dynamic>{
"id": viewId,
"event": [
'id': viewId,
'event': <dynamic>[
eventType, // int, pointer event type
event.buttons, // int, mouse button type (left, right, middle)
event.localPosition.dx, // double, global position x
Expand All @@ -222,6 +218,7 @@ class TizenViewController extends PlatformViewController {
if (_state != _TizenViewState.created) {
return Future<void>.value();
}
// print('clearFocus : $viewId');
return SystemChannels.platform_views
.invokeMethod<void>('clearFocus', viewId);
}
Expand Down Expand Up @@ -628,6 +625,7 @@ class _TizenWebViewState extends State<TizenWebView_> {

@override
void didUpdateWidget(TizenWebView_ oldWidget) {
// print('webview: didUpdateWidget()');
super.didUpdateWidget(oldWidget);

final TextDirection newLayoutDirection = _findLayoutDirection();
Expand Down Expand Up @@ -688,6 +686,7 @@ class _TizenWebViewState extends State<TizenWebView_> {
});
return;
}
// print('_onFocusChange - viewId : $_id');
SystemChannels.textInput
.invokeMethod<void>(
'TextInput.setPlatformViewClient',
Expand Down
Binary file not shown.
25 changes: 25 additions & 0 deletions packages/webview_flutter/tizen/src/webview.cc
Expand Up @@ -435,6 +435,31 @@ void WebView::DispatchKeyUpEvent(Ecore_Event_Key* keyEvent) {
p);
}

void WebView::SetSoftwareKeyboardContext(Ecore_IMF_Context* context) {
webViewInstance_->RegisterOnShowSoftwareKeyboardIfPossibleHandler(
[context](LWE::WebContainer* v) {
LOG_DEBUG("WebView - Show Keyboard()\n");
if (!context) {
LOG_ERROR("Ecore_IMF_Context NULL\n");
return;
}
ecore_imf_context_input_panel_show(context);
ecore_imf_context_focus_in(context);
});

webViewInstance_->RegisterOnHideSoftwareKeyboardIfPossibleHandler(
[context](LWE::WebContainer*) {
LOG_INFO("WebView - Hide Keyboard()\n");
if (!context) {
LOG_INFO("Ecore_IMF_Context NULL\n");
return;
}
ecore_imf_context_reset(context);
ecore_imf_context_focus_out(context);
ecore_imf_context_input_panel_hide(context);
});
}

void WebView::ClearFocus() { LOG_DEBUG("WebView::clearFocus \n"); }

void WebView::SetDirection(int direction) {
Expand Down
4 changes: 4 additions & 0 deletions packages/webview_flutter/tizen/src/webview.h
Expand Up @@ -11,6 +11,8 @@ namespace LWE {
class WebContainer;
}

class TextInputChannel;

class WebView : public PlatformView {
public:
WebView(flutter::PluginRegistrar* registrar, int viewId,
Expand All @@ -28,6 +30,8 @@ class WebView : public PlatformView {
virtual void DispatchKeyDownEvent(Ecore_Event_Key* key) override;
virtual void DispatchKeyUpEvent(Ecore_Event_Key* key) override;

virtual void SetSoftwareKeyboardContext(Ecore_IMF_Context* context) override;

private:
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& method_call,
Expand Down

0 comments on commit 2fcca1d

Please sign in to comment.