Skip to content

[webview_flutter] Handle CompositionEvent #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
62 changes: 41 additions & 21 deletions packages/webview_flutter/tizen/src/webview.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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_