Reland "[M130 Migration][VD] Support Pointer Lock API for WRT" 75/324775/6
authorKaren Molato <k.molato@samsung.com>
Mon, 26 May 2025 07:58:47 +0000 (07:58 +0000)
committerBot Blink <blinkbot@samsung.com>
Wed, 28 May 2025 08:25:45 +0000 (08:25 +0000)
This reverts commit e4a6e3c9b78471959452737bdc2affa96898cddf.

Reason for revert: Fixed intermittent build error

--

The Pointer Lock API is WASM team's requirement for WebApp from tizen 5.5.

  Now we support the Pointer Lock API as below:
  1. Element.requestPointerLock()
  2. Document.exitPointerLock()
  3. Document: pointerlockchange
  4. Document.onpointerlockchange
  5. Document: pointerlockerrors
  6. Document.onpointerlockerror
  7. Document.pointerLockElement
  Refer:https://www.w3.org/TR/pointerlock/

Reference: https://archive.tizen.org/gerrit/310527

Change-Id: I0a504cfbf00783518295494c737652076aec252f
Signed-off-by: Karen Rose Molato <k.molato@samsung.com>
12 files changed:
content/browser/renderer_host/render_widget_host_view_aura.cc
content/browser/renderer_host/render_widget_host_view_aura.h
third_party/blink/renderer/core/dom/document.cc
third_party/blink/renderer/core/dom/element.cc
tizen_src/chromium_impl/content/browser/browser_efl.gni
tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.cc [new file with mode: 0644]
tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.h [new file with mode: 0644]
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_common_helper_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_common_helper_efl.h
tizen_src/chromium_impl/ui/ozone/platform/efl/BUILD.gn
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_event_handler.cc
tizen_src/chromium_impl/ui/ozone/platform/efl/efl_event_handler.h

index 546430528f46e1bf420f5d4e91c7648a490a03c7..73bb67a39d47ed9e59d0483d7dae8665341f3861 100644 (file)
 #include "ui/display/device_display_info_efl.h"
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.h"
+#include "ui/ozone/platform/efl/efl_event_handler.h"
+#endif
+
 #if BUILDFLAG(IS_OZONE)
 #include "ui/ozone/public/ozone_platform.h"
 #endif
@@ -345,6 +350,10 @@ RenderWidgetHostViewAura::RenderWidgetHostViewAura(
   if (aura_efl_helper())
     aura_efl_helper()->SetOrientation(rotation_);
 #endif
+
+#if BUILDFLAG(IS_TIZEN_TV)
+  pointer_lock_ = std::make_unique<PointerLock>(this, &web_contents);
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -1033,7 +1042,16 @@ void RenderWidgetHostViewAura::WindowTitleChanged() {
 }
 
 bool RenderWidgetHostViewAura::IsPointerLocked() {
+#if BUILDFLAG(IS_TIZEN_TV)
+  ui::EflEventHandler* efl_event_handler =
+      efl_helper_ ? efl_helper_->GetEventHandler() : nullptr;
+  if (!efl_event_handler)
+    return false;
+
+  return efl_event_handler->IsMouseLocked();
+#else
   return event_handler_->mouse_locked();
+#endif
 }
 
 gfx::Size RenderWidgetHostViewAura::GetVisibleViewportSize() {
@@ -1518,7 +1536,17 @@ void RenderWidgetHostViewAura::SetMainFrameAXTreeID(ui::AXTreeID id) {
 
 blink::mojom::PointerLockResult RenderWidgetHostViewAura::LockPointer(
     bool request_unadjusted_movement) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  ui::EflEventHandler* efl_event_handler =
+      efl_helper_ ? efl_helper_->GetEventHandler() : nullptr;
+  if (!efl_event_handler)
+    return blink::mojom::PointerLockResult::kWrongDocument;
+
+  efl_event_handler->SetPointerLock(pointer_lock_.get());
+  return efl_event_handler->LockMouse();
+#else
   return event_handler_->LockPointer(request_unadjusted_movement);
+#endif
 }
 
 blink::mojom::PointerLockResult RenderWidgetHostViewAura::ChangePointerLock(
@@ -1527,7 +1555,14 @@ blink::mojom::PointerLockResult RenderWidgetHostViewAura::ChangePointerLock(
 }
 
 void RenderWidgetHostViewAura::UnlockPointer() {
+#if BUILDFLAG(IS_TIZEN_TV)
+  ui::EflEventHandler* efl_event_handler =
+      efl_helper_ ? efl_helper_->GetEventHandler() : nullptr;
+  if (efl_event_handler)
+    efl_event_handler->UnlockMouse();
+#else
   event_handler_->UnlockPointer();
+#endif
 }
 
 bool RenderWidgetHostViewAura::
index 3c4912c1c54da806317b535327d98d4b00c35154..cbc12f9ecc66a3706fd314ee2d5b7b1a6e157250 100644 (file)
@@ -80,6 +80,9 @@ namespace ui {
 enum class DomCode : uint32_t;
 class InputMethod;
 class LocatedEvent;
+#if BUILDFLAG(IS_TIZEN_TV)
+class EflEventHandler;
+#endif
 }
 
 namespace wm {
@@ -92,6 +95,10 @@ class LegacyRenderWidgetHostHWND;
 class DirectManipulationBrowserTestBase;
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+class PointerLock;
+#endif
+
 class DelegatedFrameHost;
 class DelegatedFrameHostClient;
 class MouseWheelPhaseHandler;
@@ -919,6 +926,7 @@ class CONTENT_EXPORT RenderWidgetHostViewAura
 
 #if BUILDFLAG(IS_TIZEN_TV)
   bool is_default_focused_view_ = false;
+  std::unique_ptr<PointerLock> pointer_lock_;
 #endif
 
 #if defined(TIZEN_VIDEO_HOLE)
index 09dbcbac93dcebaa7783fcd502bb72d64b5a17d6..e9b3008fe57054d3be7fb9934eb5810889d32223 100644 (file)
@@ -8163,6 +8163,7 @@ void Document::SetPopoverPointerdownTarget(const HTMLElement* popover) {
 }
 
 void Document::exitPointerLock() {
+  LOG(INFO) << "request exitPointerLock";
   if (!GetPage())
     return;
   if (Element* target = GetPage()->GetPointerLockController().GetElement()) {
index fa63766943350b0de36c4dcaa8ca2a20feb4f1e3..5deaa05a4af1fd741af57287d7cccea29e6bdff2 100644 (file)
@@ -8789,6 +8789,7 @@ ScriptPromise<IDLUndefined> Element::requestPointerLock(
     ScriptState* script_state,
     const PointerLockOptions* options,
     ExceptionState& exception_state) {
+  LOG(INFO) << "request PointerLock";
   if (!GetDocument().GetPage()) {
     return ScriptPromise<IDLUndefined>::RejectWithDOMException(
         script_state, MakeGarbageCollected<DOMException>(
index 1041778368637be108b3ca22a8ccee4e51fbf804..b0257962542f84bb048902356eb448a79a733aa5 100644 (file)
@@ -193,6 +193,13 @@ if (tizen_multimedia) {
   ]
 }
 
+if (tizen_product_tv) {
+  external_content_browser_efl_sources += [
+    "//tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.cc",
+    "//tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.h",
+  ]
+}
+
 if (tizen_pepper_extensions && enable_plugins) {
   external_content_browser_efl_sources += [
     "//tizen_src/chromium_impl/content/browser/renderer_host/pepper/browser_pepper_host_factory_efl.cc",
diff --git a/tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.cc b/tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.cc
new file mode 100644 (file)
index 0000000..06b9eb2
--- /dev/null
@@ -0,0 +1,266 @@
+// Copyright 2019 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/pointer_lock.h"
+
+#include "content/browser/renderer_host/render_widget_host_view_aura.h"
+#include "content/browser/renderer_host/rwhv_aura_common_helper_efl.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "efl/ecore_x_wayland_wrapper.h"
+#include "efl/window_factory.h"
+#include "ewk/efl_integration/common/application_type.h"
+#include "ui/events/event.h"
+
+namespace content {
+
+namespace {
+// In mouse lock mode, we need to prevent the (invisible) cursor from hitting
+// the border of the view, in order to get valid movement information. However,
+// forcing the cursor back to the center of the view after each mouse move
+// doesn't work well. It reduces the frequency of useful mouse move messages
+// significantly. Therefore, we move the cursor to the center of the view only
+// if it approaches the border. |kMouseLockBorderPercentage| specifies the width
+// of the border area, in percentage of the corresponding dimension.
+const int kMouseLockBorderPercentage = 15;
+
+}  // namespace
+
+PointerLock::PointerLock(RenderWidgetHostViewAura* rwhva,
+                         content::WebContents* web_contents)
+    : rwhva_(rwhva), web_contents_(web_contents) {
+  evas_ = GetEvas();
+  if (!evas_)
+    LOG(ERROR) << "GetEvas failed!";
+
+  efl_helper_ = rwhva_->aura_efl_helper();
+  if (!efl_helper_)
+    LOG(ERROR) << "efl_helper is null!";
+
+  unlocked_cursor_type_ = WebCursor(ui::mojom::CursorType::kPointer);
+}
+
+PointerLock::~PointerLock() {}
+
+void PointerLock::UpdateUnlockedCursorType(const WebCursor& webcursor) {
+  // In locking process,we no need save the fake cursor type:kTypeTVNone
+  if (!in_locking_process)
+    unlocked_cursor_type_ = webcursor;
+}
+
+void PointerLock::HideCursor() {
+  LOG(INFO) << "HideCursor";
+  if (efl_helper_)
+    efl_helper_->UpdateCursor(WebCursor(ui::mojom::CursorType::kNone));
+}
+
+void PointerLock::ShowCursor() {
+  LOG(INFO) << "ShowCursor";
+  if (efl_helper_)
+    efl_helper_->UpdateCursor(unlocked_cursor_type_);
+}
+
+void PointerLock::LockCursor() {
+  is_mouse_locked_ = true;
+
+  // Record the start lock position
+  LOG(INFO) << "start mouse_position X:" << unlocked_global_mouse_position_.x()
+            << ",Y:" << unlocked_global_mouse_position_.y();
+}
+
+void PointerLock::UnlockCursor() {
+  is_mouse_locked_ = false;
+}
+
+bool PointerLock::IsMouseLocked() {
+  return is_mouse_locked_;
+}
+
+bool PointerLock::IsPointLockEnabled() {
+  // now only support point lock api for WRT
+  if (content::IsTIZENWRT())
+    return true;
+  return false;
+}
+
+void PointerLock::MoveCursorToOriginal() {
+  // Ensure that the global mouse position is updated here to its original
+  // value. If we don't do this then the synthesized mouse move which is posted
+  // after the cursor is moved ends up getting a large movement delta which is
+  // not what sites expect. The delta is computed in the
+  // ModifyEventMovementAndCoords function.
+  Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_);
+  ecore_evas_pointer_warp(ee, unlocked_global_mouse_position_.x(),
+                          unlocked_global_mouse_position_.y());
+  ecore_wl2_sync();
+  LOG(INFO) << "Move Cursor To Original,x:"
+            << unlocked_global_mouse_position_.x()
+            << ",y:" << unlocked_global_mouse_position_.y();
+}
+
+void PointerLock::ModifyEventMovementAndCoords(ui::MouseEvent* event) {
+  const float sf = rwhva_->GetDeviceScaleFactor();
+  float screen_x = evas_coord_world_x_to_screen(evas_, event->x()) / sf;
+  float screen_y = evas_coord_world_x_to_screen(evas_, event->y()) / sf;
+  float client_x = event->x() / sf;
+  float client_y = event->y() / sf;
+
+  // If the mouse has just entered, we must report zero movementX/Y. Hence we
+  // reset any global_mouse_position set previously.
+  if (event->type() == ui::EventType::kMouseEntered ||
+      event->type() == ui::EventType::kMouseExited) {
+    global_mouse_position_.SetPoint(screen_x, screen_y);
+    LOG(INFO) << "mouse_position X:" << global_mouse_position_.x()
+              << ",Y:" << global_mouse_position_.y();
+  }
+
+  // Movement is computed by taking the difference of the new cursor position
+  // and the previous. Under mouse lock the cursor will be warped back to the
+  // center so that we are not limited by clipping boundaries.
+  // We do not measure movement as the delta from cursor to center because
+  // we may receive more mouse movement events before our warp has taken
+  // effect.
+  // TODO(crbug.com/802067): We store event coordinates as pointF but
+  // movement_x/y are integer. In order not to lose fractional part, we need
+  // to keep the movement calculation as "floor(cur_pos) - floor(last_pos)".
+  // Remove the floor here when movement_x/y is changed to double.
+
+  // Because EFL can not update mouse position timely when we set to center
+  // So we don't set the current mouse position to center until we get the
+  // center position.
+  if (pending_center_move_) {
+    gfx::PointF center_in_screen(rwhva_->GetViewBounds().CenterPoint());
+    if (screen_x == center_in_screen.x() && screen_y == center_in_screen.y()) {
+      LOG(INFO) << "current mouse position is center,set "
+                   "global_mouse_position_ to center";
+      global_mouse_position_ = center_in_screen;
+      pending_center_move_ = false;
+    }
+  }
+
+  ui::MouseEvent::DispatcherApi(event).set_movement(gfx::Vector2dF(
+      base::ClampFloor(screen_x) - base::ClampFloor(global_mouse_position_.x()),
+      base::ClampFloor(screen_y) -
+          base::ClampFloor(global_mouse_position_.y())));
+
+  // Record the previous_mouse_position
+  global_mouse_position_.SetPoint(screen_x, screen_y);
+
+  // Under mouse lock, coordinates of mouse are locked to what they were when
+  // mouse lock was entered.
+  if (IsMouseLocked()) {
+    event->set_location_f(unlocked_mouse_position_);
+    event->set_root_location_f(unlocked_global_mouse_position_);
+  } else {
+    unlocked_mouse_position_.SetPoint(client_x, client_y);
+    unlocked_global_mouse_position_.SetPoint(screen_x, screen_y);
+  }
+}
+
+bool PointerLock::ShouldMoveToCenter() {
+  gfx::Rect view_rect = rwhva_->GetViewBounds();
+  float border_x = view_rect.width() * kMouseLockBorderPercentage / 100.0;
+  float border_y = view_rect.height() * kMouseLockBorderPercentage / 100.0;
+
+  return global_mouse_position_.x() < view_rect.x() + border_x ||
+         global_mouse_position_.x() > view_rect.right() - border_x ||
+         global_mouse_position_.y() < view_rect.y() + border_y ||
+         global_mouse_position_.y() > view_rect.bottom() - border_y;
+}
+
+void PointerLock::MoveCursorToCenter() {
+  gfx::PointF center_in_screen(rwhva_->GetViewBounds().CenterPoint());
+
+  // Because EFL can not update mouse position timely when we set to center
+  // So we don't set the current mouse position to center until we get the
+  // center position.
+  LOG(INFO) << "MoveCursorToCenter,center position,X:" << center_in_screen.x()
+            << ",Y:" << center_in_screen.y();
+  pending_center_move_ = true;
+
+  // Move Cursor To Center
+  Ecore_Evas* ee = ecore_evas_ecore_evas_get(evas_);
+  ecore_evas_pointer_warp(ee, center_in_screen.x(), center_in_screen.y());
+  ecore_wl2_sync();
+}
+
+void PointerLock::HandleMouseEventForLock(ui::MouseEvent* event) {
+  ModifyEventMovementAndCoords(event);
+
+  // Check if the mouse has reached the border and needs to be centered.
+  if (IsMouseLocked()) {
+    if (ShouldMoveToCenter())
+      MoveCursorToCenter();
+  }
+}
+
+bool PointerLock::LockMouse() {
+  LOG(INFO) << "LockMouse";
+
+  if (!IsPointLockEnabled())
+    return false;
+
+  if (IsMouseLocked())
+    return true;
+
+  in_locking_process = true;
+
+  // HideCursor
+  HideCursor();
+
+  // LockCursor
+  LockCursor();
+
+  // MoveCursor To Center if needed
+  if (ShouldMoveToCenter()) {
+    MoveCursorToCenter();
+  }
+
+  // SetTooltipsEnabled(false)
+
+  in_locking_process = false;
+
+  return true;
+}
+
+void PointerLock::UnlockMouse() {
+  LOG(INFO) << "UnlockMouse";
+
+  if (!IsPointLockEnabled())
+    return;
+
+  if (!IsMouseLocked())
+    return;
+
+  // MoveCursorToOriginal
+  MoveCursorToOriginal();
+
+  // UnlockCursor
+  UnlockCursor();
+
+  // ShowCursor
+  ShowCursor();
+
+  // SetTooltipsEnabled(true)
+
+  // response lost mouse lock
+  if (auto* rwhi = rwhva_->host())
+    rwhi->LostPointerLock();
+}
+
+Evas* PointerLock::GetEvas() {
+  if (!web_contents_)
+    return nullptr;
+
+  WebContentsImpl* wci = static_cast<WebContentsImpl*>(web_contents_);
+  if (!wci)
+    return nullptr;
+
+  Evas_Object* ewk_view = static_cast<Evas_Object*>(wci->ewk_view());
+  if (!ewk_view)
+    return nullptr;
+
+  return evas_object_evas_get(ewk_view);
+}
+}  // namespace content
\ No newline at end of file
diff --git a/tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.h b/tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.h
new file mode 100644 (file)
index 0000000..5032e5a
--- /dev/null
@@ -0,0 +1,114 @@
+// Copyright 2019 Samsung Electronics. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef POINTER_LOCK_H
+#define POINTER_LOCK_H
+
+#include <Ecore_Evas.h>
+#include <ui/gfx/geometry/point_f.h>
+#include "content/common/cursors/webcursor.h"
+#include "content/common/cursors/webcursor_efl.h"
+
+namespace ui {
+class MouseEvent;
+}
+
+namespace content {
+
+class RenderWidgetHostViewAura;
+class WebContents;
+class RWHVAuraCommonHelperEfl;
+
+class PointerLock {
+ public:
+  PointerLock(RenderWidgetHostViewAura* rwhva,
+              content::WebContents* web_contents);
+  ~PointerLock();
+
+  // Hides the cursor. Mouse events keep being sent even when the cursor is
+  // invisible.
+  void HideCursor();
+
+  // Shows the cursor. This does not take effect When mouse events are disabled.
+  void ShowCursor();
+
+  // Locks the cursor change. The cursor type, cursor visibility, and mouse
+  // events enable state never change as long as lock is held by anyone.
+  void LockCursor();
+
+  // Unlocks the cursor change. If all the locks are released, the cursor type,
+  // cursor visibility, and mouse events enable state are restored to the ones
+  // set by the lastest call of SetCursor, ShowCursor/HideCursor, and
+  // EnableMouseEvents/DisableMouseEvents.
+  void UnlockCursor();
+
+  // Check pointer is locked or not
+  bool IsMouseLocked();
+
+  // Check pointer lock api enabled or not
+  bool IsPointLockEnabled();
+
+  // Ensure that the global mouse position is updated here to its original
+  // value. If we don't do this then the synthesized mouse move which is posted
+  // after the cursor is moved ends up getting a large movement delta which is
+  // not what sites expect. The delta is computed in the
+  // ModifyEventMovementAndCoords function.
+  void MoveCursorToOriginal();
+
+  // This method computes movementX/Y and keeps track of mouse location for
+  // mouse lock on all mouse move events.
+  // |ui_mouse_event| contains the mouse event received.
+  // |event| contains the WebMouseEvent being modified.
+  void ModifyEventMovementAndCoords(ui::MouseEvent* event);
+
+  // Helper method to determine if, in mouse locked mode, the cursor should be
+  // moved to center.
+  bool ShouldMoveToCenter();
+
+  // This method moves cursor to window center for pointer lock.
+  void MoveCursorToCenter();
+
+  void HandleMouseEventForLock(ui::MouseEvent* event);
+
+  // Record the cursor type when unlocked
+  void UpdateUnlockedCursorType(const WebCursor& webcursor);
+
+  bool LockMouse();
+
+  void UnlockMouse();
+
+  Evas* GetEvas();
+
+ private:
+  RenderWidgetHostViewAura* rwhva_ = nullptr;
+  content::WebContents* web_contents_ = nullptr;
+  RWHVAuraCommonHelperEfl* efl_helper_ = nullptr;
+
+  Evas* evas_ = nullptr;
+
+  // For mouse lock
+  bool is_mouse_locked_ = false;
+
+  // Record the locking process flag
+  bool in_locking_process = false;
+
+  // Record mouse been moved to center by manual
+  bool pending_center_move_ = false;
+
+  // Last cursor position relative to screen. Used to compute movementX/Y.
+  gfx::PointF global_mouse_position_;
+
+  // Used to record the last position of the mouse when lock was entered.
+  // Relative to the upper-left corner of the view.
+  gfx::PointF unlocked_mouse_position_;
+
+  // Relative to the upper-left corner of the screen.
+  gfx::PointF unlocked_global_mouse_position_;
+
+  // Record the cursor type when unlocked
+  WebCursor unlocked_cursor_type_;
+};
+
+}  // namespace content
+#endif
\ No newline at end of file
index ffa53194e64117ceffb3e89fd2ef2a228baced5c..dffcc0394a38e7b2b30cc1ee7a424df02465dc53 100644 (file)
@@ -43,6 +43,7 @@
 #include "content/common/cursors/webcursor.h"
 #include "ewk/efl_integration/common/application_type.h"
 #include "third_party/skia/include/core/SkBitmap.h"
+#include "tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.h"
 #include "ui/gfx/geometry/size.h"
 
 #define VD_CURSOR_THEME_NAME "vd-cursors"
@@ -1037,6 +1038,17 @@ void RWHVAuraCommonHelperEfl::UpdateCursor(const WebCursor& webcursor) {
       LOG(INFO) << "UpdateCursor,mouse_events_enabled_ false,just return";
       return;
     }
+
+    if (efl_event_handler->IsMouseLocked()) {
+      LOG(INFO)
+          << "UpdateCursor,MouseLocked,keep on nuncursor style,JUST RETURN";
+      return;
+    }
+
+    // Record the unlocked cursor type for show original cursor when unlocked
+    PointerLock* pointer_lock = efl_event_handler->GetPointerLock();
+    if (pointer_lock && pointer_lock->IsPointLockEnabled())
+      pointer_lock->UpdateUnlockedCursorType(webcursor);
   }
 
   UpdateCursorName(webcursor);
index 6d9d9e79ded01574ff5c0718bbd7544bbb407311..cce5cd7c4945d1221bcae6f3baefad79e4b3a80f 100644 (file)
@@ -69,6 +69,10 @@ class SelectionControllerEfl;
 class WebContents;
 class WebContentsDelegate;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+class PointerLock;
+#endif
+
 class CONTENT_EXPORT RWHVAuraCommonHelperEfl {
  public:
   RWHVAuraCommonHelperEfl(
@@ -210,6 +214,7 @@ class CONTENT_EXPORT RWHVAuraCommonHelperEfl {
   void OnSelectionRectReceived(const gfx::Rect& selection_rect);
   void UpdateTooltipUnderCursor(const std::u16string&);
   void SetRWHHelperForIMContextEfl();
+  ui::EflEventHandler* GetEventHandler();
   ui::IMContextEfl* GetIMContextEfl();
 #if defined(TIZEN_PASSKEY_SUPPORT)
   void DisplayQRCode(std::string contents);
@@ -232,7 +237,6 @@ class CONTENT_EXPORT RWHVAuraCommonHelperEfl {
   gfx::Size frame_data_output_size_;
 
  private:
-  ui::EflEventHandler* GetEventHandler();
   void CreateSelectionControllerEfl();
 
   bool is_focused_node_editable_ = false;
index 7444d9222a9bc828ea8f3cec944acb3d51869ea3..0a62023e100bd440bfa8a1e10f61bb1e9b3f3958 100644 (file)
@@ -89,10 +89,12 @@ source_set("efl") {
 
   deps = [
     "//base",
+    "//content/public/common:interfaces_headers",
     "//mojo/public/cpp/bindings",
     "//mojo/public/cpp/system",
     "//skia",
     "//tizen_src/chromium_impl/tizen:system-info",
+    "//third_party/blink/public/mojom:mojom_platform_headers",
     "//ui/base",
     "//ui/base:buildflags",
     "//ui/base/cursor",
index 13b4459156a942827c8c382d5b3b8a4f5965ef56..7539143ca6c2db9600afd243f0ba2f4ada1e3841 100644 (file)
@@ -35,6 +35,7 @@
 #include "base/command_line.h"
 #include "third_party/blink/public/platform/web_application_type.h"
 #include "tizen/tizen_tv_platform.h"
+#include "tizen_src/chromium_impl/content/browser/renderer_host/pointer_lock.h"
 #include "tizen_src/chromium_impl/ui/base/clipboard/clipboard_helper_efl.h"
 #endif
 
@@ -633,6 +634,11 @@ void EflEventHandler::OnMouseDown(void* data,
     LOG(INFO) << "handle as MouseEvents";
     MouseEvent event = MakeWebMouseEvent(EventType::kMousePressed, ev,
                                          thiz->GetTopControlsHeight());
+#if BUILDFLAG(IS_TIZEN_TV)
+    // Handle Mouse Event For Lock
+    if (thiz->pointer_lock_ && thiz->pointer_lock_->IsPointLockEnabled())
+      thiz->pointer_lock_->HandleMouseEventForLock(&event);
+#endif
     EflPlatformEventSource::GetInstance()->DispatchEflEvent(&event);
 #if BUILDFLAG(IS_TIZEN_TV)
     if (!thiz->on_mouse_down_callback_.is_null()) {
@@ -666,6 +672,11 @@ void EflEventHandler::OnMouseUp(void* data,
   } else if (thiz->GetMouseEventsEnabled(ev)) {
     MouseEvent event = MakeWebMouseEvent(EventType::kMouseReleased, ev,
                                          thiz->GetTopControlsHeight());
+#if BUILDFLAG(IS_TIZEN_TV)
+    // Handle Mouse Event For Lock
+    if (thiz->pointer_lock_ && thiz->pointer_lock_->IsPointLockEnabled())
+      thiz->pointer_lock_->HandleMouseEventForLock(&event);
+#endif
     EflPlatformEventSource::GetInstance()->DispatchEflEvent(&event);
 #if BUILDFLAG(IS_TIZEN_TV)
     if (!thiz->on_mouse_up_callback_.is_null() &&
@@ -699,10 +710,23 @@ void EflEventHandler::OnMouseMove(void* data,
     event_flags |= button;
     MouseEvent event(EventType::kMouseMoved, location, root_location,
                      base::TimeTicks::Now(), event_flags, button);
+
+#if BUILDFLAG(IS_TIZEN_TV)
+    // Handle Mouse Event For Lock
+    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)));
+#endif
     EflPlatformEventSource::GetInstance()->DispatchEflEvent(&event);
 #if BUILDFLAG(IS_TIZEN_TV)
     if (!thiz->on_mouse_move_callback_.is_null())
@@ -789,6 +813,14 @@ void EflEventHandler::OnKeyDown(void* data,
 
 #if BUILDFLAG(IS_TIZEN_TV)
   bool is_register_mode = false;
+  // when point lock status,press "ESC" ,exit point lock
+  if (thiz->IsMouseLocked() && !strcmp(key_down->key, "XF86Back")) {
+    LOG(INFO) << "press ESC or Return,exit point lock when point lock status.";
+    thiz->was_keydown_filtered_as_exit_point_lock_ = true;
+    thiz->UnlockMouse();
+    return;
+  }
+
   if (!thiz->key_event_checker_.is_null() &&
       !thiz->key_event_checker_.Run(event_info, true, &is_register_mode)) {
     return;
@@ -852,6 +884,14 @@ void EflEventHandler::OnKeyUp(void* data,
 
 #if BUILDFLAG(IS_TIZEN_TV)
   bool is_register_mode = false;
+  // when point lock status,press "ESC" ,exit point lock
+  if (!strcmp(key_up->key, "XF86Back") &&
+      thiz->was_keydown_filtered_as_exit_point_lock_) {
+    thiz->was_keydown_filtered_as_exit_point_lock_ = false;
+    LOG(INFO) << "press ESC or Return,exit point lock when point lock status.";
+    return;
+  }
+
   if (!thiz->key_event_checker_.is_null() &&
       !thiz->key_event_checker_.Run(event_info, false, &is_register_mode)) {
     return;
@@ -1083,6 +1123,27 @@ bool EflEventHandler::IsMouseOnPopupMenu() const {
 
   return false;
 }
+
+bool EflEventHandler::IsMouseLocked() {
+  if (!pointer_lock_)
+    return false;
+
+  return pointer_lock_->IsMouseLocked();
+}
+
+blink::mojom::PointerLockResult EflEventHandler::LockMouse() {
+  LOG(INFO) << "LockMouse";
+  if (pointer_lock_ && pointer_lock_->LockMouse())
+    return blink::mojom::PointerLockResult::kSuccess;
+  else
+    return blink::mojom::PointerLockResult::kUnsupportedOptions;
+}
+
+void EflEventHandler::UnlockMouse() {
+  LOG(INFO) << "UnlockMouse";
+  if (pointer_lock_)
+    pointer_lock_->UnlockMouse();
+}
 #endif
 
 void EflEventHandler::OnMultiTouchDownEvent(void* data,
index 8ed2c1aff1c6ca96fa08400cf3b1e49c62180ed9..9e5fd58b9dd644e0759718d2de39f8df663ccc26 100644 (file)
 
 #if BUILDFLAG(IS_TIZEN_TV)
 #include "base/functional/callback.h"
+#include "third_party/blink/public/mojom/input/pointer_lock_result.mojom.h"
 #include "ui/gfx/geometry/rect.h"
+
+namespace content {
+class PointerLock;
+}  // namespace content
 #endif
 
 namespace ui {
@@ -81,6 +86,13 @@ class EflEventHandler {
   void SetKeyEventChecker(
       const base::RepeatingCallback<bool(void*, bool, bool*)>& checker);
   EflWindow* window() { return window_; }
+  void SetPointerLock(content::PointerLock* pointer_lock) {
+    pointer_lock_ = pointer_lock;
+  }
+  content::PointerLock* GetPointerLock() { return pointer_lock_; }
+  bool IsMouseLocked();
+  blink::mojom::PointerLockResult LockMouse();
+  void UnlockMouse();
 #endif
 
  private:
@@ -152,6 +164,8 @@ class EflEventHandler {
   base::RepeatingCallback<void(void)> on_mouse_move_callback_;
   bool popup_visible_ = false;
   gfx::Rect popup_bounds_ = gfx::Rect(0, 0, 0, 0);
+  content::PointerLock* pointer_lock_ = nullptr;
+  bool was_keydown_filtered_as_exit_point_lock_ = false;
 #endif
 };