Skip to content

Commit 1b6eeed

Browse files
authored
[webview_flutter] Handle CompositionEvent (#47)
* Pass a composition event sent by the flutter engine to the webview plugin * Handle a clear focus event
1 parent 791511e commit 1b6eeed

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed
Binary file not shown.
Binary file not shown.

packages/webview_flutter/tizen/src/webview.cc

+41-21
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
160160
height_(height),
161161
tbmSurface_(nullptr),
162162
isMouseLButtonDown_(false),
163-
hasNavigationDelegate_(false) {
163+
hasNavigationDelegate_(false),
164+
context_(nullptr) {
164165
SetTextureId(FlutterRegisterExternalTexture(textureRegistrar_));
165166
InitWebView();
166167

@@ -697,32 +698,51 @@ void WebView::DispatchKeyUpEvent(Ecore_Event_Key* keyEvent) {
697698
p);
698699
}
699700

701+
void WebView::DispatchCompositionUpdateEvent(const char* str, int size) {
702+
LOG_DEBUG("WebView::DispatchCompositionUpdateEvent [%s]", str);
703+
webViewInstance_->DispatchCompositionUpdateEvent(std::string(str, size));
704+
}
705+
706+
void WebView::DispatchCompositionEndEvent(const char* str, int size) {
707+
LOG_DEBUG("WebView::DispatchCompositionEndEvent [%s]", str);
708+
webViewInstance_->DispatchCompositionEndEvent(std::string(str, size));
709+
}
710+
711+
void WebView::ShowPanel() {
712+
LOG_DEBUG("WebView - Show Keyboard()\n");
713+
if (!context_) {
714+
LOG_ERROR("Ecore_IMF_Context NULL\n");
715+
return;
716+
}
717+
ecore_imf_context_input_panel_show(context_);
718+
ecore_imf_context_focus_in(context_);
719+
}
720+
721+
void WebView::HidePanel() {
722+
LOG_DEBUG("WebView - Hide Keyboard()\n");
723+
if (!context_) {
724+
LOG_ERROR("Ecore_IMF_Context NULL\n");
725+
return;
726+
}
727+
ecore_imf_context_reset(context_);
728+
ecore_imf_context_focus_out(context_);
729+
ecore_imf_context_input_panel_hide(context_);
730+
}
731+
700732
void WebView::SetSoftwareKeyboardContext(Ecore_IMF_Context* context) {
733+
context_ = context;
734+
701735
webViewInstance_->RegisterOnShowSoftwareKeyboardIfPossibleHandler(
702-
[context](LWE::WebContainer* v) {
703-
LOG_DEBUG("WebView - Show Keyboard()\n");
704-
if (!context) {
705-
LOG_ERROR("Ecore_IMF_Context NULL\n");
706-
return;
707-
}
708-
ecore_imf_context_input_panel_show(context);
709-
ecore_imf_context_focus_in(context);
710-
});
736+
[this](LWE::WebContainer* v) { ShowPanel(); });
711737

712738
webViewInstance_->RegisterOnHideSoftwareKeyboardIfPossibleHandler(
713-
[context](LWE::WebContainer*) {
714-
LOG_INFO("WebView - Hide Keyboard()\n");
715-
if (!context) {
716-
LOG_INFO("Ecore_IMF_Context NULL\n");
717-
return;
718-
}
719-
ecore_imf_context_reset(context);
720-
ecore_imf_context_focus_out(context);
721-
ecore_imf_context_input_panel_hide(context);
722-
});
739+
[this](LWE::WebContainer*) { HidePanel(); });
723740
}
724741

725-
void WebView::ClearFocus() { LOG_DEBUG("WebView::clearFocus \n"); }
742+
void WebView::ClearFocus() {
743+
LOG_DEBUG("WebView::clearFocus \n");
744+
HidePanel();
745+
}
726746

727747
void WebView::SetDirection(int direction) {
728748
LOG_DEBUG("WebView::SetDirection direction: %d\n", direction);

packages/webview_flutter/tizen/src/webview.h

+7
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,17 @@ class WebView : public PlatformView {
3434
// Key input event
3535
virtual void DispatchKeyDownEvent(Ecore_Event_Key* key) override;
3636
virtual void DispatchKeyUpEvent(Ecore_Event_Key* key) override;
37+
virtual void DispatchCompositionUpdateEvent(const char* str,
38+
int size) override;
39+
virtual void DispatchCompositionEndEvent(const char* str, int size) override;
3740

3841
virtual void SetSoftwareKeyboardContext(Ecore_IMF_Context* context) override;
3942

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

45+
void HidePanel();
46+
void ShowPanel();
47+
4248
private:
4349
void HandleMethodCall(
4450
const flutter::MethodCall<flutter::EncodableValue>& method_call,
@@ -60,6 +66,7 @@ class WebView : public PlatformView {
6066
bool isMouseLButtonDown_;
6167
bool hasNavigationDelegate_;
6268
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
69+
Ecore_IMF_Context* context_;
6370
};
6471

6572
#endif // FLUTTER_PLUGIN_WEBVIEW_FLUTTER_TIZEN_WEVIEW_H_

0 commit comments

Comments
 (0)