Skip to content
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
4 changes: 3 additions & 1 deletion packages/webview_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## NEXT
## 0.9.6

* Update code format.
* Add support for mouse events.
* Fix crash issue by explicitly enabling touch events on TV.

## 0.9.5

Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ This package is not an _endorsed_ implementation of `webview_flutter`. Therefore
```yaml
dependencies:
webview_flutter: ^4.10.0
webview_flutter_tizen: ^0.9.5
webview_flutter_tizen: ^0.9.6
```

## Example
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: webview_flutter_tizen
description: Tizen implementation of the webview_flutter plugin.
homepage: https://github.com/flutter-tizen/plugins
repository: https://github.com/flutter-tizen/plugins/tree/master/packages/webview_flutter
version: 0.9.5
version: 0.9.6

environment:
sdk: ">=3.1.0 <4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/webview_flutter/tizen/project_def.prop
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ USER_SRCS += src/*.cc
# User defines
USER_DEFS =
USER_UNDEFS =
USER_CPP_DEFS = FLUTTER_PLUGIN_IMPL
USER_CPP_DEFS = FLUTTER_PLUGIN_IMPL WEBVIEW_TIZEN_TOUCH_EVENTS_ENABLED
USER_CPP_UNDEFS =

# User includes
Expand Down
19 changes: 18 additions & 1 deletion packages/webview_flutter/tizen/src/ewk_internal_api_binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@ bool EwkInternalApiBinding::Initialize() {
// ewk_view
view.SetBackgroundColor = reinterpret_cast<EwkViewBgColorSetFnPtr>(
dlsym(handle_, "ewk_view_bg_color_set"));
view.TouchEventsEnabledSet =
reinterpret_cast<EwkViewTouchEventsEnabledSetFnPtr>(
dlsym(handle_, "ewk_view_touch_events_enabled_set"));
view.FeedTouchEvent = reinterpret_cast<EwkViewFeedTouchEventFnPtr>(
dlsym(handle_, "ewk_view_feed_touch_event"));
view.MouseEventsEnabledSet =
reinterpret_cast<EwkViewMouseEventsEnabledSetFnPtr>(
dlsym(handle_, "ewk_view_mouse_events_enabled_set"));
view.FeedMouseDown = reinterpret_cast<EwkViewFeedMouseDownFnPtr>(
dlsym(handle_, "ewk_view_feed_mouse_down"));
view.FeedMouseUp = reinterpret_cast<EwkViewFeedMouseUpFnPtr>(
dlsym(handle_, "ewk_view_feed_mouse_up"));
view.FeedMouseMove = reinterpret_cast<EwkViewFeedMouseMoveFnPtr>(
dlsym(handle_, "ewk_view_feed_mouse_move"));
view.FeedMouseWheel = reinterpret_cast<EwkViewFeedMouseWheelFnPtr>(
dlsym(handle_, "ewk_view_feed_mouse_wheel"));
view.SendKeyEvent = reinterpret_cast<EwkViewSendKeyEventFnPtr>(
dlsym(handle_, "ewk_view_send_key_event"));
view.OffscreenRenderingEnabledSet =
Expand Down Expand Up @@ -82,7 +96,10 @@ bool EwkInternalApiBinding::Initialize() {
console_message.SourceGet = reinterpret_cast<EwkConsoleMessageSourceGetFnPtr>(
dlsym(handle_, "ewk_console_message_source_get"));

return view.SetBackgroundColor && view.FeedTouchEvent && view.SendKeyEvent &&
return view.SetBackgroundColor && view.TouchEventsEnabledSet &&
view.FeedTouchEvent && view.MouseEventsEnabledSet &&
view.FeedMouseDown && view.FeedMouseUp && view.FeedMouseMove &&
view.FeedMouseWheel && view.SendKeyEvent &&
view.OffscreenRenderingEnabledSet && view.ImeWindowSet &&
view.KeyEventsEnabledSet && view.SupportVideoHoleSet &&
view.OnJavaScriptAlert && view.OnJavaScriptConfirm &&
Expand Down
26 changes: 26 additions & 0 deletions packages/webview_flutter/tizen/src/ewk_internal_api_binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ typedef enum {

typedef struct _Ewk_Touch_Point Ewk_Touch_Point;

typedef enum {
EWK_MOUSE_BUTTON_LEFT = 1,
EWK_MOUSE_BUTTON_MIDDLE = 2,
EWK_MOUSE_BUTTON_RIGHT = 3
} Ewk_Mouse_Button_Type;

struct _Ewk_Touch_Point {
int id;
int x;
Expand All @@ -35,10 +41,24 @@ typedef Eina_Bool (*Ewk_View_JavaScript_Prompt_Callback)(

typedef Eina_Bool (*EwkViewBgColorSetFnPtr)(Evas_Object* obj, int r, int g,
int b, int a);
typedef Eina_Bool (*EwkViewTouchEventsEnabledSetFnPtr)(Evas_Object* view,
Eina_Bool enabled);
typedef Eina_Bool (*EwkViewFeedTouchEventFnPtr)(Evas_Object* obj,
Ewk_Touch_Event_Type type,
const Eina_List* points,
const Evas_Modifier* modifiers);
typedef Eina_Bool (*EwkViewMouseEventsEnabledSetFnPtr)(Evas_Object* view,
Eina_Bool enabled);
typedef Eina_Bool (*EwkViewFeedMouseDownFnPtr)(Evas_Object* obj,
Ewk_Mouse_Button_Type button,
int x, int y);
typedef Eina_Bool (*EwkViewFeedMouseUpFnPtr)(Evas_Object* obj,
Ewk_Mouse_Button_Type button,
int x, int y);
typedef Eina_Bool (*EwkViewFeedMouseMoveFnPtr)(Evas_Object* obj, int x, int y);
typedef Eina_Bool (*EwkViewFeedMouseWheelFnPtr)(Evas_Object* obj,
Eina_Bool y_direction, int step,
int x, int y);
typedef Eina_Bool (*EwkViewSendKeyEventFnPtr)(Evas_Object* obj, void* key_event,
Eina_Bool is_press);
typedef void (*EwkViewOffscreenRenderingEnabledSetFnPtr)(Evas_Object* obj,
Expand Down Expand Up @@ -67,7 +87,13 @@ typedef void (*EwkViewJavaScriptPromptReplyFnPtr)(Evas_Object* o,

typedef struct {
EwkViewBgColorSetFnPtr SetBackgroundColor = nullptr;
EwkViewTouchEventsEnabledSetFnPtr TouchEventsEnabledSet = nullptr;
EwkViewFeedTouchEventFnPtr FeedTouchEvent = nullptr;
EwkViewMouseEventsEnabledSetFnPtr MouseEventsEnabledSet = nullptr;
EwkViewFeedMouseDownFnPtr FeedMouseDown = nullptr;
EwkViewFeedMouseUpFnPtr FeedMouseUp = nullptr;
EwkViewFeedMouseMoveFnPtr FeedMouseMove = nullptr;
EwkViewFeedMouseWheelFnPtr FeedMouseWheel = nullptr;
EwkViewSendKeyEventFnPtr SendKeyEvent = nullptr;
EwkViewOffscreenRenderingEnabledSetFnPtr OffscreenRenderingEnabledSet =
nullptr;
Expand Down
85 changes: 70 additions & 15 deletions packages/webview_flutter/tizen/src/webview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <tbm_surface.h>

#include "buffer_pool.h"
#include "ewk_internal_api_binding.h"
#include "log.h"
#include "webview_factory.h"

Expand Down Expand Up @@ -223,21 +222,29 @@ void WebView::Resize(double width, double height) {
evas_object_resize(webview_instance_, width_, height_);
}

void WebView::Touch(int type, int button, double x, double y, double dx,
double dy) {
void WebView::Touch(int event_type, int button_type, double x, double y,
double dx, double dy) {
#ifdef WEBVIEW_TIZEN_TOUCH_EVENTS_ENABLED
SendTouchEvent(event_type, x, y);
#else
SendMouseEvent(event_type, button_type, x, y, dx, dy);
#endif
}

void WebView::SendTouchEvent(int event_type, double x, double y) {
Ewk_Touch_Event_Type mouse_event_type = EWK_TOUCH_START;
Evas_Touch_Point_State state = EVAS_TOUCH_POINT_DOWN;
if (type == 0) { // down event
if (event_type == 0) { // down event
mouse_event_type = EWK_TOUCH_START;
state = EVAS_TOUCH_POINT_DOWN;
} else if (type == 1) { // move event
} else if (event_type == 1) { // move event
mouse_event_type = EWK_TOUCH_MOVE;
state = EVAS_TOUCH_POINT_MOVE;
} else if (type == 2) { // up event
} else if (event_type == 2) { // up event
mouse_event_type = EWK_TOUCH_END;
state = EVAS_TOUCH_POINT_UP;
} else {
LOG_WARN("Unknown touch event type: %d", type);
LOG_WARN("Unknown touch event type: %d", event_type);
}

Eina_List* points = 0;
Expand All @@ -253,6 +260,42 @@ void WebView::Touch(int type, int button, double x, double y, double dx,
eina_list_free(points);
}

void WebView::SendMouseEvent(int event_type, int button_type, double x,
double y, double dx, double dy) {
Ewk_Mouse_Button_Type mouse_button_type = (Ewk_Mouse_Button_Type)0;
switch (button_type) {
case 1:
mouse_button_type = EWK_MOUSE_BUTTON_LEFT;
break;
case 2:
mouse_button_type = EWK_MOUSE_BUTTON_RIGHT;
break;
case 4:
mouse_button_type = EWK_MOUSE_BUTTON_MIDDLE;
break;
}

int px = x + left_;
int py = y + top_;

if (event_type == 0) { // down event
mouse_button_type_ = mouse_button_type;
EwkInternalApiBinding::GetInstance().view.FeedMouseDown(
webview_instance_, mouse_button_type_, px, py);
} else if (event_type == 1) {
if (dy != 0) {
EwkInternalApiBinding::GetInstance().view.FeedMouseWheel(
webview_instance_, true, dy > 0 ? 1 : -1, px, py);
}
} else if (event_type == 2) { // up event
EwkInternalApiBinding::GetInstance().view.FeedMouseUp(
webview_instance_, mouse_button_type_, px, py);
mouse_button_type_ = mouse_button_type;
} else {
LOG_WARN("Unknown mouse event type: %d", event_type);
}
}

bool WebView::SendKey(const char* key, const char* string, const char* compose,
uint32_t modifiers, uint32_t scan_code, bool is_down) {
if (!IsFocused()) {
Expand Down Expand Up @@ -307,13 +350,13 @@ bool WebView::InitWebView() {
chromium_argv);

// TODO(jsuya): ewk_init() and ewk_shutdown() are designed to be called only
// once in a process.(If ewk_init() is called after ewk_shutdown() is called,
// SIGTRAP is called internally.) ewk_init() initializes the efl modules and
// web engine's arguments data. The efl modules are initialized by default in
// OS, and arguments data is also initialized through SetArguments() API, so
// calling ewk_init() is not necessary. Therefore, temporarily comment out
// ewk_init() and ewk_shutdown(). It can be reverted depending on updates to
// chromium-efl.
// once in a process.(If ewk_init() is called after ewk_shutdown() is
// called, SIGTRAP is called internally.) ewk_init() initializes the efl
// modules and web engine's arguments data. The efl modules are initialized
// by default in OS, and arguments data is also initialized through
// SetArguments() API, so calling ewk_init() is not necessary. Therefore,
// temporarily comment out ewk_init() and ewk_shutdown(). It can be reverted
// depending on updates to chromium-efl.
// ewk_init();
Ecore_Evas* evas = ecore_evas_new("wayland_egl", 0, 0, 1, 1, 0);

Expand Down Expand Up @@ -342,6 +385,17 @@ bool WebView::InitWebView() {
window_);
EwkInternalApiBinding::GetInstance().view.KeyEventsEnabledSet(
webview_instance_, true);
#ifdef WEBVIEW_TIZEN_TOUCH_EVENTS_ENABLED
EwkInternalApiBinding::GetInstance().view.TouchEventsEnabledSet(
webview_instance_, true);
EwkInternalApiBinding::GetInstance().view.MouseEventsEnabledSet(
webview_instance_, false);
#else
EwkInternalApiBinding::GetInstance().view.TouchEventsEnabledSet(
webview_instance_, false);
EwkInternalApiBinding::GetInstance().view.MouseEventsEnabledSet(
webview_instance_, true);
#endif

EwkInternalApiBinding::GetInstance().view.OnJavaScriptAlert(
webview_instance_, &WebView::OnJavaScriptAlertDialog, this);
Expand Down Expand Up @@ -544,7 +598,8 @@ void WebView::HandleWebViewMethodCall(const FlMethodCall& method_call,
} else if (method_name == "getScrollPosition") {
int32_t x = 0, y = 0;
// TODO(jsuya) : ewk_view_scroll_pos_get() returns the position set in
// ewk_view_scroll_set(). Therefore, it currently does not work as intended.
// ewk_view_scroll_set(). Therefore, it currently does not work as
// intended.
ewk_view_scroll_pos_get(webview_instance_, &x, &y);
flutter::EncodableMap args = {
{flutter::EncodableValue("x"),
Expand Down
7 changes: 7 additions & 0 deletions packages/webview_flutter/tizen/src/webview.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <mutex>
#include <string>

#include "ewk_internal_api_binding.h"

typedef flutter::MethodCall<flutter::EncodableValue> FlMethodCall;
typedef flutter::MethodResult<flutter::EncodableValue> FlMethodResult;
typedef flutter::MethodChannel<flutter::EncodableValue> FlMethodChannel;
Expand Down Expand Up @@ -92,6 +94,10 @@ class WebView : public PlatformView {
const char* default_text,
void* data);

void SendTouchEvent(int type, double x, double y);
void SendMouseEvent(int type, int button, double x, double y, double dx,
double dy);

Evas_Object* webview_instance_ = nullptr;
flutter::TextureRegistrar* texture_registrar_;
bool engine_policy_ = false;
Expand All @@ -111,6 +117,7 @@ class WebView : public PlatformView {
std::mutex mutex_;
std::unique_ptr<BufferPool> tbm_pool_;
bool disposed_ = false;
Ewk_Mouse_Button_Type mouse_button_type_ = (Ewk_Mouse_Button_Type)0;
};

#endif // FLUTTER_PLUGIN_WEBVIEW_H_
Loading