[M120 Migration]Fix Mouse Position Issue in miniplayer 27/310927/4
authorfang fengrong <fr.fang@samsung.com>
Thu, 9 May 2024 09:21:57 +0000 (17:21 +0800)
committerfengrong fang <fr.fang@samsung.com>
Mon, 13 May 2024 02:54:41 +0000 (02:54 +0000)
1. On miniplayer window, the window x position is not from 0,
need minus x offset, or else will cause the screen position wrong.

2. When mouse in, set focus to efl window to fix miniplayer without focus issue.

refer:
https://review.tizen.org/gerrit/#/c/299719/

Change-Id: I5abb5e3f496ac417cee82f7f347dec81887af778
Signed-off-by: fang fengrong <fr.fang@samsung.com>
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_event_handler.cc

index 7640d12d8033e9c3b49706657640e31f04bff627..9804d2fa2a16c030f1a2766c973ccb5c4fcd5de9 100644 (file)
@@ -79,14 +79,12 @@ bool IsRCDevice(Evas_Device_Class device_id, const std::string device_name) {
 
 enum { kLeftButton = 1, kMiddleButton = 2, kRightButton = 3 };
 
-#if BUILDFLAG(IS_TIZEN_TV)
 static void TranslateEvasCoordToWebKitCoord(Evas_Object* web_view,
                                             gfx::PointF* point) {
   Evas_Coord tmpX, tmpY;
   evas_object_geometry_get(web_view, &tmpX, &tmpY, 0, 0);
   point->Offset(-tmpX, -tmpY);
 }
-#endif
 
 EventFlags EvasToUIMouseButton(int button) {
   if (button == kLeftButton)
@@ -224,10 +222,16 @@ bool EflEventHandler::GetTouchEventsEnabled(const EVT* evas_evt) {
 }
 
 template <class EVT>
-MouseEvent MakeWebMouseEvent(EventType type, const EVT* ev, int delta_y) {
-  gfx::PointF root_location(ev->canvas.x, ev->canvas.y);
-  gfx::PointF location(ev->canvas.x, ev->canvas.y);
-  location.Offset(0, -delta_y);
+MouseEvent MakeWebMouseEvent(EventType type,
+                             const EVT* ev,
+                             Evas* evas,
+                             Evas_Object* obj) {
+  const float sf = GetDeviceScaleFactor();
+  gfx::PointF root_location(
+      evas_coord_world_x_to_screen(evas, ev->canvas.x) / sf,
+      evas_coord_world_y_to_screen(evas, ev->canvas.y) / sf);
+  gfx::PointF location(ev->canvas.x / sf, ev->canvas.y / sf);
+  TranslateEvasCoordToWebKitCoord(obj, &location);
   int button = EvasToUIMouseButton(ev->button);
   int event_flags = EvasModifiersToEventFlags(ev->modifiers);
   event_flags |= button;
@@ -567,8 +571,7 @@ void EflEventHandler::OnMouseDown(void* data,
   if (thiz->GetTouchEventsEnabled(ev)) {
     thiz->ProcessTouchEvents(ev->timestamp, false);
   } else {
-    MouseEvent event =
-        MakeWebMouseEvent(ET_MOUSE_PRESSED, ev, thiz->GetTopControlsHeight());
+    MouseEvent event = MakeWebMouseEvent(ET_MOUSE_PRESSED, ev, evas, obj);
 #if BUILDFLAG(IS_TIZEN_TV)
     // Handle Mouse Event For Lock
     if (thiz->pointer_lock_ && thiz->pointer_lock_->IsPointLockEnabled())
@@ -604,8 +607,7 @@ void EflEventHandler::OnMouseUp(void* data,
   if (thiz->GetTouchEventsEnabled(ev)) {
     thiz->ProcessTouchEvents(ev->timestamp, false);
   } else {
-    MouseEvent event =
-        MakeWebMouseEvent(ET_MOUSE_RELEASED, ev, thiz->GetTopControlsHeight());
+    MouseEvent event = MakeWebMouseEvent(ET_MOUSE_RELEASED, ev, evas, obj);
 
 #if BUILDFLAG(IS_TIZEN_TV)
     // Handle Mouse Event For Lock
@@ -638,9 +640,12 @@ void EflEventHandler::OnMouseMove(void* data,
   if (thiz->GetTouchEventsEnabled(ev)) {
     thiz->ProcessTouchEvents(ev->timestamp, false);
   } else {
-    gfx::PointF location(ev->cur.canvas.x, ev->cur.canvas.y);
-    gfx::PointF root_location(ev->cur.canvas.x, ev->cur.canvas.y);
-    location.Offset(0, -thiz->GetTopControlsHeight());
+    const float sf = GetDeviceScaleFactor();
+    gfx::PointF location(ev->cur.canvas.x / sf, ev->cur.canvas.y / sf);
+    gfx::PointF root_location(
+        evas_coord_world_x_to_screen(evas, ev->cur.canvas.x) / sf,
+        evas_coord_world_y_to_screen(evas, ev->cur.canvas.y) / sf);
+    TranslateEvasCoordToWebKitCoord(obj, &location);
     int button = EvasToUIMouseButton(ev->buttons);
     int event_flags = EvasModifiersToEventFlags(ev->modifiers);
     event_flags |= button;
@@ -652,13 +657,11 @@ void EflEventHandler::OnMouseMove(void* data,
     if (thiz->pointer_lock_ && thiz->pointer_lock_->IsPointLockEnabled()) {
       thiz->pointer_lock_->HandleMouseEventForLock(&event);
     } else {
-      const float sf = GetDeviceScaleFactor();
       ui::MouseEvent::DispatcherApi(&event).set_movement(
           gfx::Vector2dF((ev->cur.canvas.x / sf - ev->prev.canvas.x / sf),
                          (ev->cur.canvas.y / sf - ev->prev.canvas.y / sf)));
     }
 #else
-    const float sf = GetDeviceScaleFactor();
     ui::MouseEvent::DispatcherApi(&event).set_movement(
         gfx::Vector2dF((ev->cur.canvas.x / sf - ev->prev.canvas.x / sf),
                        (ev->cur.canvas.y / sf - ev->prev.canvas.y / sf)));
@@ -698,10 +701,13 @@ void EflEventHandler::OnMouseOut(void* data,
   thiz->window_->UpdateFocus(false);
 #endif
   Evas_Event_Mouse_Out* ev = static_cast<Evas_Event_Mouse_Out*>(event_info);
+  const float sf = GetDeviceScaleFactor();
 
-  gfx::PointF root_location(ev->canvas.x, ev->canvas.y);
-  gfx::PointF location(ev->canvas.x, ev->canvas.y);
-  location.Offset(0, -thiz->GetTopControlsHeight());
+  gfx::PointF root_location(
+      evas_coord_world_x_to_screen(evas, ev->canvas.x) / sf,
+      evas_coord_world_y_to_screen(evas, ev->canvas.y) / sf);
+  gfx::PointF location(ev->canvas.x / sf, ev->canvas.y / sf);
+  TranslateEvasCoordToWebKitCoord(obj, &location);
   int button = EvasToUIMouseButton(ev->buttons);
   int event_flags = EvasModifiersToEventFlags(ev->modifiers);
   event_flags |= button;
@@ -725,9 +731,12 @@ void EflEventHandler::OnMouseWheel(void* data,
   else
     offset.set_y(-(ev->z * kDefaultScrollStep));
 
-  gfx::PointF root_location(ev->canvas.x, ev->canvas.y);
-  gfx::PointF location(ev->canvas.x, ev->canvas.y);
-  location.Offset(0, -thiz->GetTopControlsHeight());
+  const float sf = GetDeviceScaleFactor();
+  gfx::PointF root_location(
+      evas_coord_world_x_to_screen(evas, ev->canvas.x) / sf,
+      evas_coord_world_y_to_screen(evas, ev->canvas.y) / sf);
+  gfx::PointF location(ev->canvas.x / sf, ev->canvas.y / sf);
+  TranslateEvasCoordToWebKitCoord(obj, &location);
   int event_flags = EvasModifiersToEventFlags(ev->modifiers);
   MouseWheelEvent event(offset, location, root_location, base::TimeTicks::Now(),
                         event_flags, 0);