Skip to content
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

Implement key events for tizen webview #14

Merged
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
33 changes: 33 additions & 0 deletions shell/platform/tizen/channels/platform_view_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ PlatformViewChannel::~PlatformViewChannel() {
view_instances_.clear();
}

void PlatformViewChannel::sendKeyEvent(Ecore_Event_Key* key, bool is_down) {
auto instances = viewInstances();
auto it = instances.find(currentFocusedViewId());
if (it != instances.end()) {
if (is_down) {
it->second->dispatchKeyDownEvent(key);
} else {
it->second->dispatchKeyUpEvent(key);
}
}
}

int PlatformViewChannel::currentFocusedViewId() {
for (auto it = view_instances_.begin(); it != view_instances_.end(); it++) {
if (it->second->isFocused()) {
return it->second->getViewId();
}
}
return -1;
}

void PlatformViewChannel::HandleMethodCall(
const flutter::MethodCall<flutter::EncodableValue>& call,
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
Expand All @@ -113,10 +134,22 @@ void PlatformViewChannel::HandleMethodCall(
}
auto it = view_factories_.find(viewType);
if (it != view_factories_.end()) {
auto focuesdView = view_instances_.find(currentFocusedViewId());
if (focuesdView != view_instances_.end()) {
focuesdView->second->setFocus(false);
}

auto viewInstance =
it->second->create(viewId, width, height, byteMessage);
viewInstance->setFocus(true);
view_instances_.insert(
std::pair<int, PlatformView*>(viewId, viewInstance));

if (channel_ != nullptr) {
auto id = std::make_unique<flutter::EncodableValue>(viewId);
channel_->InvokeMethod("viewFocused", std::move(id));
}

result->Success(flutter::EncodableValue(viewInstance->getTextureId()));
} else {
LoggerE("can't find view type = %s", viewType.c_str());
Expand Down
6 changes: 6 additions & 0 deletions shell/platform/tizen/channels/platform_view_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef EMBEDDER_PLATFORM_VIEW_CHANNEL_H_
#define EMBEDDER_PLATFORM_VIEW_CHANNEL_H_

#include <Ecore_Input.h>

#include <map>

#include "flutter/shell/platform/common/cpp/client_wrapper/include/flutter/binary_messenger.h"
Expand All @@ -20,6 +22,10 @@ class PlatformViewChannel {
std::map<std::string, std::unique_ptr<PlatformViewFactory>>& viewFactories() {
return view_factories_;
}
std::map<int, PlatformView*>& viewInstances() { return view_instances_; }

void sendKeyEvent(Ecore_Event_Key* key, bool is_down);
int currentFocusedViewId();

private:
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/tizen/channels/text_input_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ static constexpr char kMultilineInputType[] = "TextInputType.multiline";
static constexpr char kUpdateEditingStateMethod[] =
"TextInputClient.updateEditingState";
static constexpr char kPerformActionMethod[] = "TextInputClient.performAction";
static constexpr char kSetPlatformViewClient[] =
"TextInput.setPlatformViewClient";
static constexpr char kTextInputAction[] = "inputAction";
static constexpr char kTextInputType[] = "inputType";
static constexpr char kTextInputTypeName[] = "name";
Expand Down Expand Up @@ -329,6 +331,8 @@ void TextInputChannel::HandleMethodCall(
ShowSoftwareKeyboard();
} else if (method.compare(kHideMethod) == 0) {
HideSoftwareKeyboard();
} else if (method.compare(kSetPlatformViewClient) == 0) {
// TODO: implement if necessary
} else if (method.compare(kClearClientMethod) == 0) {
active_model_ = nullptr;
} else if (method.compare(kSetClientMethod) == 0) {
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/tizen/key_event_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ Eina_Bool KeyEventHandler::OnKey(void *data, int type, void *event) {
if (engine->key_event_channel) {
engine->key_event_channel->SendKeyEvent(key, is_down);
}
if (engine->platform_view_channel) {
engine->platform_view_channel->sendKeyEvent(key, is_down);
}
}
return ECORE_CALLBACK_PASS_ON;
}
13 changes: 12 additions & 1 deletion shell/platform/tizen/public/flutter_platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_
#define FLUTTER_SHELL_PLATFORM_TIZEN_PUBLIC_FLUTTER_PLATFORM_VIEW_H_

#include <Ecore_Input.h>
#include <stddef.h>
#include <stdint.h>

Expand All @@ -15,7 +16,10 @@ using ByteMessage = std::vector<uint8_t>;
class PlatformView {
public:
PlatformView(flutter::PluginRegistrar* registrar, int viewId)
: registrar_(registrar), viewId_(viewId), textureId_(0) {}
: registrar_(registrar),
viewId_(viewId),
textureId_(0),
isFocused_(false) {}
virtual ~PlatformView() {}
int getViewId() { return viewId_; }
int getTextureId() { return textureId_; }
Expand All @@ -27,11 +31,18 @@ class PlatformView {
double dy) = 0;
virtual void setDirection(int direction) = 0;
virtual void clearFocus() = 0;
void setFocus(bool f) { isFocused_ = f; }
bool isFocused() { return isFocused_; }

// Key input event
virtual void dispatchKeyDownEvent(Ecore_Event_Key* key) = 0;
virtual void dispatchKeyUpEvent(Ecore_Event_Key* key) = 0;

private:
flutter::PluginRegistrar* registrar_;
int viewId_;
int textureId_;
bool isFocused_;
};

class PlatformViewFactory {
Expand Down