Skip to content

Commit

Permalink
[webview_flutter] Handle CompositionEvent (flutter-tizen#47)
Browse files Browse the repository at this point in the history
* Pass a composition event sent by the flutter engine to the webview plugin
* Handle a clear focus event
  • Loading branch information
seungsoo47 committed Mar 19, 2021
1 parent 791511e commit 1b6eeed
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
Binary file not shown.
Binary file not shown.
62 changes: 41 additions & 21 deletions packages/webview_flutter/tizen/src/webview.cc
Expand Up @@ -160,7 +160,8 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
height_(height),
tbmSurface_(nullptr),
isMouseLButtonDown_(false),
hasNavigationDelegate_(false) {
hasNavigationDelegate_(false),
context_(nullptr) {
SetTextureId(FlutterRegisterExternalTexture(textureRegistrar_));
InitWebView();

Expand Down Expand Up @@ -697,32 +698,51 @@ void WebView::DispatchKeyUpEvent(Ecore_Event_Key* keyEvent) {
p);
}

void WebView::DispatchCompositionUpdateEvent(const char* str, int size) {
LOG_DEBUG("WebView::DispatchCompositionUpdateEvent [%s]", str);
webViewInstance_->DispatchCompositionUpdateEvent(std::string(str, size));
}

void WebView::DispatchCompositionEndEvent(const char* str, int size) {
LOG_DEBUG("WebView::DispatchCompositionEndEvent [%s]", str);
webViewInstance_->DispatchCompositionEndEvent(std::string(str, size));
}

void WebView::ShowPanel() {
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_);
}

void WebView::HidePanel() {
LOG_DEBUG("WebView - Hide Keyboard()\n");
if (!context_) {
LOG_ERROR("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::SetSoftwareKeyboardContext(Ecore_IMF_Context* context) {
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);
});
[this](LWE::WebContainer* v) { ShowPanel(); });

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);
});
[this](LWE::WebContainer*) { HidePanel(); });
}

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

void WebView::SetDirection(int direction) {
LOG_DEBUG("WebView::SetDirection direction: %d\n", direction);
Expand Down
7 changes: 7 additions & 0 deletions packages/webview_flutter/tizen/src/webview.h
Expand Up @@ -34,11 +34,17 @@ class WebView : public PlatformView {
// Key input event
virtual void DispatchKeyDownEvent(Ecore_Event_Key* key) override;
virtual void DispatchKeyUpEvent(Ecore_Event_Key* key) override;
virtual void DispatchCompositionUpdateEvent(const char* str,
int size) override;
virtual void DispatchCompositionEndEvent(const char* str, int size) override;

virtual void SetSoftwareKeyboardContext(Ecore_IMF_Context* context) override;

LWE::WebContainer* GetWebViewInstance() { return webViewInstance_; }

void HidePanel();
void ShowPanel();

private:
void HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& method_call,
Expand All @@ -60,6 +66,7 @@ class WebView : public PlatformView {
bool isMouseLButtonDown_;
bool hasNavigationDelegate_;
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
Ecore_IMF_Context* context_;
};

#endif // FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_H_

0 comments on commit 1b6eeed

Please sign in to comment.