[M85 Migration][API] Change unit for ewk_view_scroll_* APIs from dip to device pixel 18/245318/2
authoryh106.jung <yh106.jung@samsung.com>
Tue, 1 Aug 2017 06:19:17 +0000 (15:19 +0900)
committerBot Blink <blinkbot@samsung.com>
Mon, 12 Oct 2020 07:02:50 +0000 (07:02 +0000)
Below APIs had used device pixel as their unit on Tizen 2.4.
So, this patch changes unit from dip to device pixel for them.
- ewk_view_scroll_pos_get
- ewk_view_scroll_set
- ewk_view_scroll_size_get

References:
https://review.tizen.org/gerrit/c/platform/framework/web/chromium-efl/+/220052

Change-Id: I19d23aa93da0e5efb96d3fd07da11eaa8026974c
Signed-off-by: yh106.jung <yh106.jung@samsung.com>
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h

index 579271f..5960294 100644 (file)
@@ -167,6 +167,8 @@ EWebView::EWebView(Ewk_Context* context, Evas_Object* object)
       hit_test_completion_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
                            base::WaitableEvent::InitialState::NOT_SIGNALED),
       page_scale_factor_(1.0),
+      x_delta_(0.0),
+      y_delta_(0.0),
       is_initialized_(false) {}
 
 void EWebView::Initialize() {
@@ -1153,33 +1155,67 @@ void EWebView::SetScale(double scale_factor, int x, int y) {
 }
 
 bool EWebView::GetScrollPosition(int* x, int* y) const {
-  DCHECK(x);
-  DCHECK(y);
+  if (!rwhv()) {
+    LOG(ERROR) << "rwhv() returns nullptr";
+    return false;
+  }
 
   if (scroll_detector_->IsScrollOffsetChanged()) {
-    *x = previous_scroll_position_.x();
-    *y = previous_scroll_position_.y();
+    if (x)
+      *x = previous_scroll_position_.x();
+    if (y)
+      *y = previous_scroll_position_.y();
   } else {
-    const gfx::Vector2d scroll_position =
+    const gfx::Vector2d scroll_position_dip =
         scroll_detector_->GetLastScrollPosition();
-    *x = scroll_position.x();
-    *y = scroll_position.y();
+    const float device_scale_factor = display::Screen::GetScreen()
+                                          ->GetPrimaryDisplay()
+                                          .device_scale_factor();
+    if (x) {
+      *x = gfx::ToRoundedInt((scroll_position_dip.x() - x_delta_) *
+                             device_scale_factor);
+    }
+    if (y) {
+      *y = gfx::ToRoundedInt((scroll_position_dip.y() - y_delta_) *
+                             device_scale_factor);
+    }
   }
   return true;
 }
 
-void EWebView::SetScroll(int x, int y) {
-  RenderViewHost* render_view_host = web_contents_->GetRenderViewHost();
-  if (!render_view_host)
+void EWebView::ChangeScroll(int& x, int& y) {
+  if (!rwhv()) {
+    LOG(ERROR) << "rwhv() returns nullptr";
     return;
+  }
+
+  int max_x = 0;
+  int max_y = 0;
+  GetScrollSize(&max_x, &max_y);
+  previous_scroll_position_.set_x(std::min(std::max(x, 0), max_x));
+  previous_scroll_position_.set_y(std::min(std::max(y, 0), max_y));
 
-  int maxX, maxY;
-  GetScrollSize(&maxX, &maxY);
-  previous_scroll_position_.set_x(std::min(std::max(x, 0), maxX));
-  previous_scroll_position_.set_y(std::min(std::max(y, 0), maxY));
+  const float device_scale_factor = display::Screen::GetScreen()
+                                        ->GetPrimaryDisplay()
+                                        .device_scale_factor();
+  int x_input = x;
+  int y_input = y;
+
+  x = gfx::ToCeiledInt(x / device_scale_factor);
+  y = gfx::ToCeiledInt(y / device_scale_factor);
+
+  x_delta_ = x - (x_input / device_scale_factor);
+  y_delta_ = y - (y_input / device_scale_factor);
 
   scroll_detector_->SetScrollOffsetChanged();
+}
+
+void EWebView::SetScroll(int x, int y) {
+  RenderViewHost* render_view_host = web_contents_->GetRenderViewHost();
+  if (!render_view_host)
+    return;
 
+  ChangeScroll(x, y);
   render_view_host->Send(
       new EwkViewMsg_SetScroll(render_view_host->GetRoutingID(), x, y));
 }
index 19e0761..071ba8d 100644 (file)
@@ -506,6 +506,8 @@ class EWebView {
 
   void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
 
+  void ChangeScroll(int& x, int& y);
+
   scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
   scoped_refptr<Ewk_Context> context_;
   scoped_refptr<Ewk_Context> old_context_;
@@ -558,8 +560,8 @@ class EWebView {
   Hit_Test_Params hit_test_params_;
   base::WaitableEvent hit_test_completion_;
   double page_scale_factor_;
-  double min_page_scale_factor_;
-  double max_page_scale_factor_;
+  double x_delta_;
+  double y_delta_;
 
   WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
                   _Ewk_Geolocation_Permission_Request*>