[M108 Migration][WCS] Bringup contents magnifier 83/288683/4
authorayush.k123 <ayush.k123@samsung.com>
Tue, 21 Feb 2023 09:34:22 +0000 (15:04 +0530)
committerBot Blink <blinkbot@samsung.com>
Wed, 22 Feb 2023 14:43:50 +0000 (14:43 +0000)
This patch brings up contents magnifier.

Reference: https://review.tizen.org/gerrit/282646/

Change-Id: Ib4dcd1c5d22083c1a601f201989ce3b66eb262f4
Signed-off-by: Ayush Kumar <ayush.k123@samsung.com>
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.cc
tizen_src/chromium_impl/content/browser/renderer_host/rwhv_aura_offscreen_helper_efl.h
tizen_src/chromium_impl/content/browser/selection/selection_controller_efl.cc
tizen_src/chromium_impl/content/browser/selection/selection_controller_efl.h
tizen_src/chromium_impl/content/browser/selection/selection_magnifier_efl.cc
tizen_src/chromium_impl/content/browser/selection/selection_magnifier_efl.h

index a283e89..cf06dce 100644 (file)
@@ -465,6 +465,12 @@ void RWHVAuraOffscreenHelperEfl::PaintTextureToSurface(GLuint texture_id) {
 
   // for snapshot
   frame_rendered_ = true;
+
+  // Get snapshot for magnifier.
+  if (!magnifier_snapshot_request_.is_null()) {
+    std::move(magnifier_snapshot_request_).Run();
+    magnifier_snapshot_request_.Reset();
+  }
 }
 
 void RWHVAuraOffscreenHelperEfl::InitEvasGL() {
@@ -1309,8 +1315,10 @@ void RWHVAuraOffscreenHelperEfl::SendGestureEvent(
     blink::WebGestureEvent& event) {
   HandleGesture(event);
   blink::WebInputEvent::Type event_type = event.GetType();
-  if (event_type == blink::WebInputEvent::Type::kGestureScrollUpdate)
+  if (magnifier_ &&
+      event_type == blink::WebInputEvent::Type::kGestureScrollUpdate) {
     return;
+  }
 
   if (event_type != blink::WebInputEvent::Type::kUndefined) {
     rwhv_aura_->host()->ForwardGestureEventWithLatencyInfo(
@@ -1318,6 +1326,51 @@ void RWHVAuraOffscreenHelperEfl::SendGestureEvent(
   }
 }
 
+void RWHVAuraOffscreenHelperEfl::set_magnifier(bool status) {
+  magnifier_ = status;
+}
+
+void RWHVAuraOffscreenHelperEfl::GetMagnifierSnapshot(
+    gfx::Rect snapshot_area,
+    float scale_factor,
+    std::unique_ptr<ScreenshotCapturedCallback> cb) {
+#if defined(USE_TTRACE)
+  TTRACE(TTRACE_TAG_WEB,
+         "RenderWidgetHostViewAuraHelperEfl::GetMagnifierSnapshot");
+#endif
+  // GetSnapshot might be replaced with something designed for magnifier.
+  Evas_Object* image = GetSnapshot(snapshot_area, scale_factor, true);
+
+  base::ThreadTaskRunnerHandle::Get()->PostTask(
+      FROM_HERE,
+      base::BindOnce(&ScreenshotCapturedCallback::Run,
+                     base::Owned(cb.release()), base::Unretained(image)));
+}
+
+void RWHVAuraOffscreenHelperEfl::RequestMagnifierSnapshotAsync(
+    const Eina_Rectangle rect,
+    Screenshot_Captured_Callback callback,
+    void* user_data,
+    float scale_factor) {
+  gfx::Rect snapshot_area(rect.x, rect.y, rect.w, rect.h);
+  gfx::Rect view_rect = GetViewBoundsInPix();
+
+  // Adjust snapshot rect for email app
+  auto visible_viewport_rect = selection_controller_->GetVisibleViewportRect();
+  int hidden_view_width = visible_viewport_rect.x() - view_rect.x();
+  int hidden_view_height = visible_viewport_rect.y() - view_rect.y();
+  if (hidden_view_height || hidden_view_width) {
+    snapshot_area.set_x(snapshot_area.x() + hidden_view_width);
+    snapshot_area.set_y(snapshot_area.y() + hidden_view_height);
+  }
+
+  magnifier_snapshot_request_ =
+      base::BindOnce(&RWHVAuraOffscreenHelperEfl::GetMagnifierSnapshot,
+                     base::Unretained(this), snapshot_area, scale_factor,
+                     std::move(std::unique_ptr<ScreenshotCapturedCallback>(
+                         new ScreenshotCapturedCallback(callback, user_data))));
+}
+
 void RWHVAuraOffscreenHelperEfl::HandleGesture(blink::WebGestureEvent& event) {
   SelectionControllerEfl* controller = GetSelectionController();
   if (controller)
index e195e6b..d462660 100644 (file)
@@ -165,6 +165,11 @@ class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
   void MoveCaret(const gfx::Point& point);
   void SelectClosestWord(const gfx::Point& touch_point);
   bool HasSelectableText();
+  void set_magnifier(bool status);
+  void RequestMagnifierSnapshotAsync(const Eina_Rectangle rect,
+                                     Screenshot_Captured_Callback callback,
+                                     void* user_data,
+                                     float scale_factor = 1.0f);
 
  private:
   static void OnParentViewResize(void* data, Evas*, Evas_Object*, void*);
@@ -191,6 +196,9 @@ class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
   void RunGetSnapshotOnMainThread(const gfx::Rect snapshot_area,
                                   int request_id,
                                   float scale_factor);
+  void GetMagnifierSnapshot(gfx::Rect snapshot_area,
+                            float scale_factor,
+                            std::unique_ptr<ScreenshotCapturedCallback> cb);
 
   ui::EflEventHandler* GetEventHandler();
   ui::IMContextEfl* GetIMContextEfl();
@@ -245,11 +253,17 @@ class CONTENT_EXPORT RWHVAuraOffscreenHelperEfl {
   bool horizontal_panning_hold_ = false;
   bool vertical_panning_hold_ = false;
 
+  bool magnifier_ = false;
+
   OnFocusCallback on_focus_in_callback_;
   OnFocusCallback on_focus_out_callback_;
 
   bool is_content_editable_ = false;
   std::unique_ptr<EdgeEffect> edge_effect_;
+  // Magnifier snapshot requests are not added to snapshot_task_list_, because
+  // we only care about the last one if they piled up - we can only display
+  // one anyway.
+  SnapshotTask magnifier_snapshot_request_;
 };
 
 }  // namespace content
index ae22b6f..d6e172f 100644 (file)
@@ -518,17 +518,6 @@ void SelectionControllerEfl::HandleDragBeginNotification(
 
   handle_being_dragged_ = true;
 
-  Evas_Coord x, y;
-  evas_object_geometry_get(rwhva_->offscreen_helper()->content_image(), &x, &y,
-                           0, 0);
-  gfx::Point magnifier_point(
-      handle->GetBasePosition().x() + x,
-      handle->GetBasePosition().y() + y);
-
-  magnifier_->UpdateLocation(magnifier_point);
-  magnifier_->Move(magnifier_point);
-  magnifier_->Show();
-
   if (handle == input_handle_.get())
     return;
 
@@ -572,12 +561,6 @@ void SelectionControllerEfl::HandleDragUpdateNotification(SelectionHandleEfl* ha
   gfx::Rect view_bounds = rwhva_->offscreen_helper()->GetViewBoundsInPix();
   selection_change_reason_ = Reason::HandleDragged;
 
-  gfx::Point magnifier_point;
-  magnifier_point.set_x(handle->GetBasePosition().x() + view_bounds.x());
-  magnifier_point.set_y(handle->GetBasePosition().y() + view_bounds.y());
-  magnifier_->UpdateLocation(magnifier_point);
-  magnifier_->Move(magnifier_point);
-
   switch (handle->Type()) {
     case SelectionHandleEfl::HANDLE_TYPE_INPUT: {
       rwhva_->offscreen_helper()->MoveCaret(handle->GetBasePosition());
@@ -611,7 +594,6 @@ void SelectionControllerEfl::HandleDragEndNotification() {
   ecore_events_filter_ = nullptr;
 
   selection_change_reason_ = Reason::Irrelevant;
-  magnifier_->Hide();
   start_handle_->SetBasePosition(selection_data_->GetLeftRect().bottom_left());
   end_handle_->SetBasePosition(selection_data_->GetRightRect().bottom_right());
   handle_being_dragged_ = false;
@@ -750,7 +732,8 @@ void SelectionControllerEfl::HandleLongPressEventPrivate(
 
   gfx::Rect view_bounds = rwhva_->offscreen_helper()->GetViewBoundsInPix();
   magnifier_->HandleLongPress(gfx::Point(touch_point.x() + view_bounds.x(),
-                                         touch_point.y() + view_bounds.y()));
+                                         touch_point.y() + view_bounds.y()),
+                              selection_data_->IsInEditField());
 }
 
 void SelectionControllerEfl::HandleLongPressMoveEvent(const gfx::Point& touch_point) {
index fcf9eff..8247b16 100644 (file)
@@ -49,6 +49,7 @@ class CONTENT_EXPORT SelectionControllerEfl {
       const content::ContextMenuParams& params);
   void HandleLongPressMoveEvent(const gfx::Point& touch_point);
   void HandleLongPressEndEvent();
+  bool HandleBeingDragged() const { return handle_being_dragged_; }
 
   void PostHandleTapGesture(bool is_content_editable);
 
index 388e19c..3e863e6 100644 (file)
@@ -45,7 +45,8 @@ SelectionMagnifierEfl::~SelectionMagnifierEfl() {
     evas_object_del(container_);
 }
 
-void SelectionMagnifierEfl::HandleLongPress(const gfx::Point& touch_point) {
+void SelectionMagnifierEfl::HandleLongPress(const gfx::Point& touch_point,
+                                            bool is_in_edit_field) {
   evas_object_event_callback_add(
       controller_->rwhva()->offscreen_helper()->content_image(),
       EVAS_CALLBACK_MOUSE_MOVE, OnAnimatorMove, this);
@@ -55,8 +56,10 @@ void SelectionMagnifierEfl::HandleLongPress(const gfx::Point& touch_point) {
   // Call OnAnimatorMove here, so that the magnifier widget
   // gets properly placed. Other calls to it are expected to
   // happen as a react to finger/mouse movements.
-  OnAnimatorMove();
-  Show();
+  if (!is_in_edit_field && !controller_->HandleBeingDragged()) {
+    OnAnimatorMove();
+    Show();
+  }
 }
 
 void SelectionMagnifierEfl::DisconnectCallbacks() {
@@ -68,8 +71,11 @@ void SelectionMagnifierEfl::DisconnectCallbacks() {
       EVAS_CALLBACK_MOUSE_UP, OnAnimatorUp);
 }
 
-void SelectionMagnifierEfl::OnAnimatorMove(void* data, Evas*, Evas_Object*, void*) {
-  SelectionMagnifierEfl* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
+void SelectionMagnifierEfl::OnAnimatorMove(void* data,
+                                           Evas*,
+                                           Evas_Object*,
+                                           void*) {
+  auto* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
   DCHECK(magnifier_data);
 
   if (magnifier_data)
@@ -84,12 +90,18 @@ void SelectionMagnifierEfl::OnAnimatorMove() {
       &point.x, &point.y);
   gfx::Point display_point(point.x, point.y);
   controller_->HandleLongPressMoveEvent(display_point);
-  UpdateLocation(display_point);
-  Move(display_point);
+
+  if (controller_->GetVisibleViewportRect().Contains(display_point)) {
+    UpdateLocation(display_point);
+    Move(display_point);
+  }
 }
 
-void SelectionMagnifierEfl::OnAnimatorUp(void* data, Evas*, Evas_Object*, void*) {
-  SelectionMagnifierEfl* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
+void SelectionMagnifierEfl::OnAnimatorUp(void* data,
+                                         Evas*,
+                                         Evas_Object*,
+                                         void*) {
+  auto* magnifier_data = static_cast<SelectionMagnifierEfl*>(data);
   DCHECK(magnifier_data);
 
   if (magnifier_data)
@@ -103,10 +115,8 @@ void SelectionMagnifierEfl::OnAnimatorUp() {
 }
 
 void SelectionMagnifierEfl::MagnifierGetSnapshotCb(Evas_Object* image,
-                                                   void* user_data)
-{
-  SelectionMagnifierEfl* selection_magnifier =
-      static_cast<SelectionMagnifierEfl*>(user_data);
+                                                   void* user_data) {
+  auto* selection_magnifier = static_cast<SelectionMagnifierEfl*>(user_data);
 
   if (selection_magnifier->content_image_) {
     evas_object_del(selection_magnifier->content_image_);
@@ -116,8 +126,8 @@ void SelectionMagnifierEfl::MagnifierGetSnapshotCb(Evas_Object* image,
   selection_magnifier->content_image_ = image;
   evas_object_show(selection_magnifier->content_image_);
 
-  elm_object_part_content_set(selection_magnifier->container_,
-      "swallow", selection_magnifier->content_image_);
+  elm_object_part_content_set(selection_magnifier->container_, "swallow",
+                              selection_magnifier->content_image_);
   evas_object_pass_events_set(selection_magnifier->content_image_, EINA_TRUE);
   evas_object_clip_set(selection_magnifier->content_image_,
       selection_magnifier->container_);
@@ -127,65 +137,78 @@ void SelectionMagnifierEfl::MagnifierGetSnapshotCb(Evas_Object* image,
 }
 
 void SelectionMagnifierEfl::UpdateLocation(const gfx::Point& location) {
-  int device_x, device_y, device_width, device_height;
-  evas_object_geometry_get(
-      controller_->rwhva()->offscreen_helper()->content_image(), &device_x,
-      &device_y, &device_width, &device_height);
+  auto visible_viewport_rect = controller_->GetVisibleViewportRect();
+  int visible_viewport_x = visible_viewport_rect.x();
+  int visible_viewport_y = visible_viewport_rect.y();
+  int visible_viewport_width = visible_viewport_rect.width();
+  int visible_viewport_height = visible_viewport_rect.height();
 
   int zoomedWidth = width_ * kZoomScale;
   int zoomedHeight = height_ * kZoomScale;
 
-  if (zoomedWidth > device_width)
-    zoomedWidth = device_width;
+  if (zoomedWidth > visible_viewport_width)
+    zoomedWidth = visible_viewport_width;
 
-  if (zoomedHeight > device_height)
-    zoomedHeight = device_height;
+  if (zoomedHeight > visible_viewport_height)
+    zoomedHeight = visible_viewport_height;
 
-  gfx::Rect content_rect(location.x() - zoomedWidth/2,
-      location.y() - zoomedHeight/2,  zoomedWidth, zoomedHeight);
+  // Place screenshot area center on touch point
+  gfx::Rect content_rect(location.x() - zoomedWidth / 2,
+                         location.y() - zoomedHeight / 2, zoomedWidth,
+                         zoomedHeight);
 
-  // Adjustments for boundry conditions
-  if (content_rect.x() < device_x)
-    content_rect.set_x(device_x);
-  else if ((content_rect.x() + zoomedWidth) > device_x + device_width)
-    content_rect.set_x(device_x + device_width - zoomedWidth);
+  // Move magnifier rect so it stays inside webview area
+  if (content_rect.x() < visible_viewport_x) {
+    content_rect.set_x(visible_viewport_x);
+  } else if ((content_rect.x() + zoomedWidth) >=
+             visible_viewport_x + visible_viewport_width) {
+    content_rect.set_x(visible_viewport_x + visible_viewport_width -
+                       zoomedWidth - 1);
+  }
 
-  if (content_rect.y() < device_y) // Do not let location to be less then magnifier y value
-    content_rect.set_y(device_y);
-  else if (content_rect.y() > device_y + device_height - zoomedHeight)
-    content_rect.set_y(device_y + device_height - zoomedHeight);
+  if (content_rect.y() < visible_viewport_y) {
+    content_rect.set_y(visible_viewport_y);
+  } else if ((content_rect.y() + zoomedHeight) >=
+             visible_viewport_y + visible_viewport_height) {
+    content_rect.set_y(visible_viewport_y + visible_viewport_height -
+                       zoomedHeight - 1);
+  }
 
+  // Convert to webview parameter space
   Eina_Rectangle rect;
-  rect.x = content_rect.x();
-  rect.y = content_rect.y();
+  rect.x = content_rect.x() - visible_viewport_x;
+  rect.y = content_rect.y() - visible_viewport_y;
   rect.w = content_rect.width();
   rect.h = content_rect.height();
-#if !defined(USE_AURA)
-  RenderWidgetHostViewEfl* rwhv =
-      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
-  if (rwhv)
-    rwhv->RequestSnapshotAsync(rect, MagnifierGetSnapshotCb, this);
-#endif
+
+  controller_->rwhva()->offscreen_helper()->RequestMagnifierSnapshotAsync(
+      rect, MagnifierGetSnapshotCb, this);
 }
 
 void SelectionMagnifierEfl::Move(const gfx::Point& location) {
-  int device_x, device_y, device_width, device_height;
-  evas_object_geometry_get(
-      controller_->rwhva()->offscreen_helper()->content_image(), &device_x,
-      &device_y, &device_width, &device_height);
+  auto visible_viewport_rect = controller_->GetVisibleViewportRect();
+  int visible_viewport_x = visible_viewport_rect.x();
+  int visible_viewport_y = visible_viewport_rect.y();
+  int visible_viewport_width = visible_viewport_rect.width();
+  int visible_viewport_height = visible_viewport_rect.height();
 
   int magnifier_x = location.x();
   int magnifier_y = location.y() - height_ - kHeightOffset;
 
-  if (magnifier_y < device_y) // Do not let location to be out of screen
-    magnifier_y = device_y;
-  else if (magnifier_y > device_height + device_y - height_)
-    magnifier_y = device_height + device_y - height_;
-
-  if (magnifier_x < device_x + width_/2) // Do not let location to be out of screen
-    magnifier_x = device_x + width_/2;
-  else if (magnifier_x > device_width + device_x - width_/2)
-    magnifier_x = device_width + device_x - width_/2;
+  // Do not let location to be out of screen
+  if (magnifier_y < visible_viewport_y) {
+    magnifier_y = visible_viewport_y;
+  } else if (magnifier_y >
+             visible_viewport_height + visible_viewport_y - height_) {
+    magnifier_y = visible_viewport_height + visible_viewport_y - height_;
+  }
+  // Do not let location to be out of screen
+  if (magnifier_x < visible_viewport_x + width_ / 2) {
+    magnifier_x = visible_viewport_x + width_ / 2;
+  } else if (magnifier_x >
+             visible_viewport_width + visible_viewport_x - width_ / 2) {
+    magnifier_x = visible_viewport_width + visible_viewport_x - width_ / 2;
+  }
 
   evas_object_move(container_, magnifier_x, magnifier_y);
 }
@@ -200,12 +223,7 @@ void SelectionMagnifierEfl::Show() {
 
   shown_ = true;
   evas_object_show(container_);
-#if !defined(USE_AURA)
-  RenderWidgetHostViewEfl* rwhv =
-      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
-  if (rwhv)
-    rwhv->set_magnifier(true);
-#endif
+  controller_->rwhva()->offscreen_helper()->set_magnifier(true);
   if (controller_->rwhva()->offscreen_helper()->ewk_view()) {
     evas_object_smart_callback_call(
         controller_->rwhva()->offscreen_helper()->ewk_view(), "magnifier,show",
@@ -214,15 +232,13 @@ void SelectionMagnifierEfl::Show() {
 }
 
 void SelectionMagnifierEfl::Hide() {
+  if (!shown_)
+    return;
+
   shown_ = false;
   evas_object_hide(content_image_);
   evas_object_hide(container_);
-#if !defined(USE_AURA)
-  RenderWidgetHostViewEfl* rwhv =
-      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
-  if (rwhv)
-    rwhv->set_magnifier(false);
-#endif
+  controller_->rwhva()->offscreen_helper()->set_magnifier(false);
   if (controller_->rwhva()->offscreen_helper()->ewk_view()) {
     evas_object_smart_callback_call(
         controller_->rwhva()->offscreen_helper()->ewk_view(), "magnifier,hide",
index 53cf98e..a693783 100644 (file)
@@ -22,7 +22,7 @@ class SelectionMagnifierEfl {
   SelectionMagnifierEfl(content::SelectionControllerEfl* controller);
   ~SelectionMagnifierEfl();
 
-  void HandleLongPress(const gfx::Point& touch_point);
+  void HandleLongPress(const gfx::Point& touch_point, bool is_in_edit_field);
   void UpdateLocation(const gfx::Point& location);
   void Move(const gfx::Point& location);
   void Show();