Skip to content

Commit

Permalink
Refactor TextInputChannel (flutter#142)
Browse files Browse the repository at this point in the history
* Refactor TextInputChannel

* Introduce TizenInputMethodContext
* Do not handle key event for PlatformView in TextInputChannel
  Each PlatformView must Implement to handle key event.
  After this patch, the input panel of webview_flutter does not work properly.
  but it have to handle every key event on itself like webview_flutter_ewk does.

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* Remove unnecessary PlatformView APIs

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* Tidy up based on review

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* Always Send key event to TextInputChannel

* Use SendKeyEvent as the method name for handling key events like others.
* SendKeyEvent returns true if the key event has been handled.

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* Use #if defined() instead of #ifdef

Signed-off-by: Boram Bae <boram21.bae@samsung.com>

* Rename to ShouldNotFilterEvent

Signed-off-by: Boram Bae <boram21.bae@samsung.com>
  • Loading branch information
bbrto21 authored and swift-kim committed Dec 9, 2021
1 parent 2b871f4 commit dc76cc7
Show file tree
Hide file tree
Showing 10 changed files with 559 additions and 544 deletions.
1 change: 1 addition & 0 deletions shell/platform/tizen/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ _flutter_tizen_source = [
"flutter_tizen_texture_registrar.cc",
"key_event_handler.cc",
"tizen_event_loop.cc",
"tizen_input_method_context.cc",
"tizen_renderer.cc",
"touch_event_handler.cc",
]
Expand Down
31 changes: 2 additions & 29 deletions shell/platform/tizen/channels/platform_view_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_message_codec.h"
#include "flutter/shell/platform/common/client_wrapper/include/flutter/standard_method_codec.h"
#include "flutter/shell/platform/common/json_method_codec.h"
#include "flutter/shell/platform/tizen/channels/text_input_channel.h"
#include "flutter/shell/platform/tizen/flutter_tizen_engine.h"
#include "flutter/shell/platform/tizen/public/flutter_platform_view.h"
#include "flutter/shell/platform/tizen/tizen_log.h"
Expand All @@ -33,10 +32,8 @@ bool GetValueFromEncodableMap(const EncodableValue& arguments,
return false;
}

PlatformViewChannel::PlatformViewChannel(BinaryMessenger* messenger,
FlutterTizenEngine* engine)
: engine_(engine),
channel_(std::make_unique<MethodChannel<EncodableValue>>(
PlatformViewChannel::PlatformViewChannel(BinaryMessenger* messenger)
: channel_(std::make_unique<MethodChannel<EncodableValue>>(
messenger,
kChannelName,
&StandardMethodCodec::GetInstance())) {
Expand Down Expand Up @@ -95,23 +92,6 @@ void PlatformViewChannel::SendKeyEvent(Ecore_Event_Key* key, bool is_down) {
}
}

void PlatformViewChannel::DispatchCompositionUpdateEvent(
const std::string& key) {
auto instances = ViewInstances();
auto it = instances.find(CurrentFocusedViewId());
if (it != instances.end()) {
it->second->DispatchCompositionUpdateEvent(key.c_str(), key.size());
}
}

void PlatformViewChannel::DispatchCompositionEndEvent(const std::string& key) {
auto instances = ViewInstances();
auto it = instances.find(CurrentFocusedViewId());
if (it != instances.end()) {
it->second->DispatchCompositionEndEvent(key.c_str(), key.size());
}
}

int PlatformViewChannel::CurrentFocusedViewId() {
for (auto it = view_instances_.begin(); it != view_instances_.end(); it++) {
if (it->second->IsFocused()) {
Expand Down Expand Up @@ -162,12 +142,6 @@ void PlatformViewChannel::HandleMethodCall(
if (view_instance) {
view_instances_.insert(
std::pair<int, PlatformView*>(view_id, view_instance));

if (engine_ && engine_->text_input_channel) {
Ecore_IMF_Context* context =
engine_->text_input_channel->GetImfContext();
view_instance->SetSoftwareKeyboardContext(context);
}
result->Success(EncodableValue(view_instance->GetTextureId()));
} else {
result->Error("Can't create a webview instance!!");
Expand Down Expand Up @@ -264,5 +238,4 @@ void PlatformViewChannel::HandleMethodCall(
}
}
}

} // namespace flutter
9 changes: 1 addition & 8 deletions shell/platform/tizen/channels/platform_view_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@ class PlatformViewFactory;

namespace flutter {

class FlutterTizenEngine;

class PlatformViewChannel {
public:
explicit PlatformViewChannel(BinaryMessenger* messenger,
FlutterTizenEngine* engine);
explicit PlatformViewChannel(BinaryMessenger* messenger);
virtual ~PlatformViewChannel();

void Dispose();
Expand All @@ -41,14 +38,10 @@ class PlatformViewChannel {
void SendKeyEvent(Ecore_Event_Key* key, bool is_down);
int CurrentFocusedViewId();

void DispatchCompositionUpdateEvent(const std::string& key);
void DispatchCompositionEndEvent(const std::string& key);

private:
void HandleMethodCall(const MethodCall<EncodableValue>& call,
std::unique_ptr<MethodResult<EncodableValue>> result);

FlutterTizenEngine* engine_;
std::unique_ptr<MethodChannel<EncodableValue>> channel_;
std::map<std::string, std::unique_ptr<PlatformViewFactory>> view_factories_;
std::map<int, PlatformView*> view_instances_;
Expand Down
Loading

0 comments on commit dc76cc7

Please sign in to comment.