Skip to content

Commit 8099f35

Browse files
authored
Call a method to set imf_context in platform view channel (#24)
* Webview which inherits from platform view uses the imf_context of engine.
1 parent 7e89462 commit 8099f35

File tree

5 files changed

+37
-12
lines changed

5 files changed

+37
-12
lines changed

shell/platform/tizen/channels/platform_view_channel.cc

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_message_codec.h"
88
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/standard_method_codec.h"
99
#include "flutter/shell/platform/common/cpp/json_method_codec.h"
10+
#include "flutter/shell/platform/tizen/channels/text_input_channel.h"
1011
#include "flutter/shell/platform/tizen/public/flutter_platform_view.h"
12+
#include "flutter/shell/platform/tizen/tizen_embedder_engine.h"
1113
#include "flutter/shell/platform/tizen/tizen_log.h"
1214

1315
static constexpr char kChannelName[] = "flutter/platform_views";
@@ -63,8 +65,10 @@ flutter::EncodableList ExtractListFromMap(
6365
return flutter::EncodableList();
6466
}
6567

66-
PlatformViewChannel::PlatformViewChannel(flutter::BinaryMessenger* messenger)
67-
: channel_(
68+
PlatformViewChannel::PlatformViewChannel(flutter::BinaryMessenger* messenger,
69+
TizenEmbedderEngine* engine)
70+
: engine_(engine),
71+
channel_(
6872
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
6973
messenger, kChannelName,
7074
&flutter::StandardMethodCodec::GetInstance())) {
@@ -117,6 +121,7 @@ void PlatformViewChannel::HandleMethodCall(
117121
const auto method = call.method_name();
118122
const auto& arguments = *call.arguments();
119123

124+
FT_LOGD("method: %s", method.c_str());
120125
if (method == "create") {
121126
std::string viewType = ExtractStringFromMap(arguments, "viewType");
122127
int viewId = ExtractIntFromMap(arguments, "id");
@@ -151,10 +156,28 @@ void PlatformViewChannel::HandleMethodCall(
151156
channel_->InvokeMethod("viewFocused", std::move(id));
152157
}
153158

159+
if (engine_ && engine_->text_input_channel) {
160+
Ecore_IMF_Context* context =
161+
engine_->text_input_channel->GetImfContext();
162+
viewInstance->SetSoftwareKeyboardContext(context);
163+
}
164+
154165
result->Success(flutter::EncodableValue(viewInstance->GetTextureId()));
155166
} else {
156167
FT_LOGE("can't find view type = %s", viewType.c_str());
157-
result->Error("0", "can't find view type");
168+
result->Error("Can't find view type");
169+
}
170+
} else if (method == "clearFocus") {
171+
int viewId = -1;
172+
if (std::holds_alternative<int>(arguments)) {
173+
viewId = std::get<int>(arguments);
174+
};
175+
auto it = view_instances_.find(viewId);
176+
if (viewId >= 0 && it != view_instances_.end()) {
177+
it->second->ClearFocus();
178+
result->Success();
179+
} else {
180+
result->Error("Can't find view id");
158181
}
159182
} else {
160183
int viewId = ExtractIntFromMap(arguments, "id");
@@ -165,7 +188,6 @@ void PlatformViewChannel::HandleMethodCall(
165188
it->second->Dispose();
166189
result->Success();
167190
} else if (method == "resize") {
168-
FT_LOGD("PlatformViewChannel resize");
169191
double width = ExtractDoubleFromMap(arguments, "width");
170192
double height = ExtractDoubleFromMap(arguments, "height");
171193
it->second->Resize(width, height);
@@ -191,17 +213,12 @@ void PlatformViewChannel::HandleMethodCall(
191213
} else if (method == "setDirection") {
192214
FT_LOGD("PlatformViewChannel setDirection");
193215
result->NotImplemented();
194-
} else if (method == "clearFocus") {
195-
FT_LOGD("PlatformViewChannel clearFocus");
196-
it->second->ClearFocus();
197-
result->NotImplemented();
198216
} else {
199217
FT_LOGD("Unimplemented method: %s", method.c_str());
200218
result->NotImplemented();
201219
}
202220
} else {
203-
FT_LOGE("can't find view id");
204-
result->Error("0", "can't find view id");
221+
result->Error("Can't find view id");
205222
}
206223
}
207224
}

shell/platform/tizen/channels/platform_view_channel.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/method_channel.h"
1414
#include "rapidjson/document.h"
1515

16+
class TizenEmbedderEngine;
1617
class PlatformView;
1718
class PlatformViewFactory;
1819
class PlatformViewChannel {
1920
public:
20-
explicit PlatformViewChannel(flutter::BinaryMessenger* messenger);
21+
explicit PlatformViewChannel(flutter::BinaryMessenger* messenger,
22+
TizenEmbedderEngine* engine);
2123
virtual ~PlatformViewChannel();
2224
void Dispose();
2325
std::map<std::string, std::unique_ptr<PlatformViewFactory>>& ViewFactories() {
@@ -29,6 +31,7 @@ class PlatformViewChannel {
2931
int CurrentFocusedViewId();
3032

3133
private:
34+
TizenEmbedderEngine* engine_;
3235
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
3336
std::map<std::string, std::unique_ptr<PlatformViewFactory>> view_factories_;
3437
std::map<int, PlatformView*> view_instances_;

shell/platform/tizen/channels/text_input_channel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class TextInputChannel {
3636
return current_keyboard_geometry_;
3737
}
3838

39+
Ecore_IMF_Context* GetImfContext() { return imf_context_; }
40+
3941
int32_t rotation = 0;
4042

4143
private:

shell/platform/tizen/public/flutter_platform_view.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_
66
#define FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_
77

8+
#include <Ecore_IMF.h>
89
#include <Ecore_Input.h>
910
#include <stddef.h>
1011
#include <stdint.h>
@@ -38,6 +39,8 @@ class PlatformView {
3839
virtual void DispatchKeyDownEvent(Ecore_Event_Key* key) = 0;
3940
virtual void DispatchKeyUpEvent(Ecore_Event_Key* key) = 0;
4041

42+
virtual void SetSoftwareKeyboardContext(Ecore_IMF_Context* context) = 0;
43+
4144
private:
4245
flutter::PluginRegistrar* registrar_;
4346
int viewId_;

shell/platform/tizen/tizen_embedder_engine.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ bool TizenEmbedderEngine::RunEngine(
188188
localization_channel->SendLocales();
189189
lifecycle_channel = std::make_unique<LifecycleChannel>(flutter_engine);
190190
platform_view_channel = std::make_unique<PlatformViewChannel>(
191-
internal_plugin_registrar_->messenger());
191+
internal_plugin_registrar_->messenger(), this);
192192

193193
key_event_handler_ = std::make_unique<KeyEventHandler>(this);
194194
touch_event_handler_ = std::make_unique<TouchEventHandler>(this);

0 commit comments

Comments
 (0)