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

Fix scroll issue #6

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
35 changes: 30 additions & 5 deletions shell/platform/tizen/touch_event_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@
#include "flutter/shell/platform/tizen/logger.h"
#include "flutter/shell/platform/tizen/tizen_embedder_engine.h"

static const int DIRECTION_VERTICAL = 0;
static const int DIRECTION_HORIZONTAL = 1;

TouchEventHandler::TouchEventHandler(TizenEmbedderEngine *engine)
: engine_(engine) {
touch_event_handlers_.push_back(
ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, OnTouch, this));
touch_event_handlers_.push_back(
ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, OnTouch, this));
touch_event_handlers_.push_back(
ecore_event_handler_add(ECORE_EVENT_MOUSE_WHEEL, OnTouch, this));
touch_event_handlers_.push_back(
ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, OnTouch, this));
touch_event_handlers_.push_back(ecore_event_handler_add(
Expand All @@ -28,6 +33,8 @@ TouchEventHandler::~TouchEventHandler() {

void TouchEventHandler::SendFlutterPointerEvent(FlutterPointerPhase phase,
double x, double y,
double scroll_delta_x,
double scroll_delta_y,
size_t timestamp) {
if (!engine_->flutter_engine) {
return;
Expand All @@ -53,7 +60,12 @@ void TouchEventHandler::SendFlutterPointerEvent(FlutterPointerPhase phase,
event.phase = phase;
event.x = new_x;
event.y = new_y;
event.timestamp = timestamp;
if (scroll_delta_x != 0 || scroll_delta_y != 0) {
event.signal_kind = kFlutterPointerSignalKindScroll;
}
event.scroll_delta_x = scroll_delta_x;
event.scroll_delta_y = scroll_delta_y;
event.timestamp = timestamp / 1000;
FlutterEngineSendPointerEvent(engine_->flutter_engine, &event, 1);
}

Expand All @@ -63,25 +75,38 @@ Eina_Bool TouchEventHandler::OnTouch(void *data, int type, void *event) {
if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN) {
self->pointer_state_ = true;
auto *button_event = reinterpret_cast<Ecore_Event_Mouse_Button *>(event);
self->SendFlutterPointerEvent(kDown, button_event->x, button_event->y,
self->SendFlutterPointerEvent(kDown, button_event->x, button_event->y, 0, 0,
button_event->timestamp);
} else if (type == ECORE_EVENT_MOUSE_BUTTON_UP) {
self->pointer_state_ = false;
auto *button_event = reinterpret_cast<Ecore_Event_Mouse_Button *>(event);
self->SendFlutterPointerEvent(kUp, button_event->x, button_event->y,
self->SendFlutterPointerEvent(kUp, button_event->x, button_event->y, 0, 0,
button_event->timestamp);
} else if (type == ECORE_EVENT_MOUSE_MOVE) {
if (self->pointer_state_) {
auto *move_event = reinterpret_cast<Ecore_Event_Mouse_Move *>(event);
self->SendFlutterPointerEvent(kMove, move_event->x, move_event->y,
self->SendFlutterPointerEvent(kMove, move_event->x, move_event->y, 0, 0,
move_event->timestamp);
}
} else if (type == ECORE_WL2_EVENT_WINDOW_VISIBILITY_CHANGE) {
auto *focus_event =
reinterpret_cast<Ecore_Wl2_Event_Window_Visibility_Change *>(event);
LoggerD("Visibility changed: %u, %d", focus_event->win,
focus_event->fully_obscured);
} else if (type == ECORE_EVENT_MOUSE_WHEEL) {
auto *wheel_event = reinterpret_cast<Ecore_Event_Mouse_Wheel *>(event);
double scroll_delta_x = 0.0, scroll_delta_y = 0.0;
if (wheel_event->direction == DIRECTION_VERTICAL) {
scroll_delta_y += wheel_event->z;
} else if (wheel_event->direction == DIRECTION_HORIZONTAL) {
scroll_delta_x += wheel_event->z;
}
const int kScrollOffsetMultiplier = 20;
scroll_delta_x *= kScrollOffsetMultiplier;
scroll_delta_y *= kScrollOffsetMultiplier;
self->SendFlutterPointerEvent(
self->pointer_state_ ? kMove : kHover, wheel_event->x, wheel_event->y,
scroll_delta_x, scroll_delta_y, wheel_event->timestamp);
}

return ECORE_CALLBACK_PASS_ON;
}
1 change: 1 addition & 0 deletions shell/platform/tizen/touch_event_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class TouchEventHandler {
bool pointer_state_ = false;

void SendFlutterPointerEvent(FlutterPointerPhase phase, double x, double y,
double scroll_delta_x, double scroll_delta_y,
size_t timestamp);

static Eina_Bool OnTouch(void* data, int type, void* event);
Expand Down