Skip to content

Commit 26a6f7c

Browse files
authored
Implement key events for tizen webview (flutter-tizen#14)
* Send key event messages from engine to plugin native about a current focused view
1 parent 766e177 commit 26a6f7c

File tree

5 files changed

+58
-1
lines changed

5 files changed

+58
-1
lines changed

shell/platform/tizen/channels/platform_view_channel.cc

+33
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,27 @@ PlatformViewChannel::~PlatformViewChannel() {
8989
view_instances_.clear();
9090
}
9191

92+
void PlatformViewChannel::sendKeyEvent(Ecore_Event_Key* key, bool is_down) {
93+
auto instances = viewInstances();
94+
auto it = instances.find(currentFocusedViewId());
95+
if (it != instances.end()) {
96+
if (is_down) {
97+
it->second->dispatchKeyDownEvent(key);
98+
} else {
99+
it->second->dispatchKeyUpEvent(key);
100+
}
101+
}
102+
}
103+
104+
int PlatformViewChannel::currentFocusedViewId() {
105+
for (auto it = view_instances_.begin(); it != view_instances_.end(); it++) {
106+
if (it->second->isFocused()) {
107+
return it->second->getViewId();
108+
}
109+
}
110+
return -1;
111+
}
112+
92113
void PlatformViewChannel::HandleMethodCall(
93114
const flutter::MethodCall<flutter::EncodableValue>& call,
94115
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
@@ -113,10 +134,22 @@ void PlatformViewChannel::HandleMethodCall(
113134
}
114135
auto it = view_factories_.find(viewType);
115136
if (it != view_factories_.end()) {
137+
auto focuesdView = view_instances_.find(currentFocusedViewId());
138+
if (focuesdView != view_instances_.end()) {
139+
focuesdView->second->setFocus(false);
140+
}
141+
116142
auto viewInstance =
117143
it->second->create(viewId, width, height, byteMessage);
144+
viewInstance->setFocus(true);
118145
view_instances_.insert(
119146
std::pair<int, PlatformView*>(viewId, viewInstance));
147+
148+
if (channel_ != nullptr) {
149+
auto id = std::make_unique<flutter::EncodableValue>(viewId);
150+
channel_->InvokeMethod("viewFocused", std::move(id));
151+
}
152+
120153
result->Success(flutter::EncodableValue(viewInstance->getTextureId()));
121154
} else {
122155
LoggerE("can't find view type = %s", viewType.c_str());

shell/platform/tizen/channels/platform_view_channel.h

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#ifndef EMBEDDER_PLATFORM_VIEW_CHANNEL_H_
66
#define EMBEDDER_PLATFORM_VIEW_CHANNEL_H_
77

8+
#include <Ecore_Input.h>
9+
810
#include <map>
911

1012
#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h"
@@ -20,6 +22,10 @@ class PlatformViewChannel {
2022
std::map<std::string, std::unique_ptr<PlatformViewFactory>>& viewFactories() {
2123
return view_factories_;
2224
}
25+
std::map<int, PlatformView*>& viewInstances() { return view_instances_; }
26+
27+
void sendKeyEvent(Ecore_Event_Key* key, bool is_down);
28+
int currentFocusedViewId();
2329

2430
private:
2531
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;

shell/platform/tizen/channels/text_input_channel.cc

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ static constexpr char kMultilineInputType[] = "TextInputType.multiline";
2121
static constexpr char kUpdateEditingStateMethod[] =
2222
"TextInputClient.updateEditingState";
2323
static constexpr char kPerformActionMethod[] = "TextInputClient.performAction";
24+
static constexpr char kSetPlatformViewClient[] =
25+
"TextInput.setPlatformViewClient";
2426
static constexpr char kTextInputAction[] = "inputAction";
2527
static constexpr char kTextInputType[] = "inputType";
2628
static constexpr char kTextInputTypeName[] = "name";
@@ -329,6 +331,8 @@ void TextInputChannel::HandleMethodCall(
329331
ShowSoftwareKeyboard();
330332
} else if (method.compare(kHideMethod) == 0) {
331333
HideSoftwareKeyboard();
334+
} else if (method.compare(kSetPlatformViewClient) == 0) {
335+
// TODO: implement if necessary
332336
} else if (method.compare(kClearClientMethod) == 0) {
333337
active_model_ = nullptr;
334338
} else if (method.compare(kSetClientMethod) == 0) {

shell/platform/tizen/key_event_handler.cc

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ Eina_Bool KeyEventHandler::OnKey(void *data, int type, void *event) {
4747
if (engine->key_event_channel) {
4848
engine->key_event_channel->SendKeyEvent(key, is_down);
4949
}
50+
if (engine->platform_view_channel) {
51+
engine->platform_view_channel->sendKeyEvent(key, is_down);
52+
}
5053
}
5154
return ECORE_CALLBACK_PASS_ON;
5255
}

shell/platform/tizen/public/flutter_platform_view.h

+12-1
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_Input.h>
89
#include <stddef.h>
910
#include <stdint.h>
1011

@@ -15,7 +16,10 @@ using ByteMessage = std::vector<uint8_t>;
1516
class PlatformView {
1617
public:
1718
PlatformView(flutter::PluginRegistrar* registrar, int viewId)
18-
: registrar_(registrar), viewId_(viewId), textureId_(0) {}
19+
: registrar_(registrar),
20+
viewId_(viewId),
21+
textureId_(0),
22+
isFocused_(false) {}
1923
virtual ~PlatformView() {}
2024
int getViewId() { return viewId_; }
2125
int getTextureId() { return textureId_; }
@@ -27,11 +31,18 @@ class PlatformView {
2731
double dy) = 0;
2832
virtual void setDirection(int direction) = 0;
2933
virtual void clearFocus() = 0;
34+
void setFocus(bool f) { isFocused_ = f; }
35+
bool isFocused() { return isFocused_; }
36+
37+
// Key input event
38+
virtual void dispatchKeyDownEvent(Ecore_Event_Key* key) = 0;
39+
virtual void dispatchKeyUpEvent(Ecore_Event_Key* key) = 0;
3040

3141
private:
3242
flutter::PluginRegistrar* registrar_;
3343
int viewId_;
3444
int textureId_;
45+
bool isFocused_;
3546
};
3647

3748
class PlatformViewFactory {

0 commit comments

Comments
 (0)