Move ScrollDetector from rwhv to ewebview
authoryh106.jung <yh106.jung@samsung.com>
Fri, 20 Mar 2015 04:01:38 +0000 (13:01 +0900)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
This patch moves ScrollDetector from rwhv to ewebview,
and moves IPC event handling for Scroll events to
web_view_browser_message_filter as well.
Also EWebView::SetScroll and EWebView::GetScrollPosition are enabled.

Change-Id: Ibbd98dab8118ab5422462aa26ffe5afa3fec0fb6
Signed-off-by: yh106.jung <yh106.jung@samsung.com>
tizen_src/ewk/efl_integration/browser/web_view_browser_message_filter.cc
tizen_src/ewk/efl_integration/efl_integration.gypi
tizen_src/ewk/efl_integration/eweb_view.cc
tizen_src/ewk/efl_integration/eweb_view.h
tizen_src/ewk/efl_integration/scroll_detector.cc [moved from tizen_src/impl/browser/renderer_host/scroll_detector.cc with 58% similarity]
tizen_src/ewk/efl_integration/scroll_detector.h [moved from tizen_src/impl/browser/renderer_host/scroll_detector.h with 63% similarity]

index e64fded..41adb66 100644 (file)
@@ -130,6 +130,16 @@ class WebViewBrowserMessageFilterPrivate
       web_view_->OnSnapshot(pixData, size.width(), size.height(), snapshotId);
   }
 
+  void OnDidChangeMaxScrollOffset(int maxScrollX, int maxScrollY) {
+    if (web_view_)
+      web_view_->GetScrollDetector()->SetMaxScroll(maxScrollX, maxScrollY);
+  }
+
+  void OnDidChangeScrollOffset(int scrollX, int scrollY) {
+    if (web_view_)
+      web_view_->GetScrollDetector()->OnChangeScrollOffset(gfx::Vector2d(scrollX, scrollY));
+  }
+
   void OnGetTextAtPositionReply(const std::string& text) {
 #ifdef TIZEN_CONTENTS_DETECTION
     if (web_view_) {
@@ -215,6 +225,10 @@ bool WebViewBrowserMessageFilter::OnMessageReceived(
         WebViewBrowserMessageFilterPrivate::OnDidChangePageScaleFactor)
     IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangePageScaleRange, private_,
         WebViewBrowserMessageFilterPrivate::OnDidChangePageScaleRange)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangeMaxScrollOffset, private_,
+        WebViewBrowserMessageFilterPrivate::OnDidChangeMaxScrollOffset)
+    IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangeScrollOffset, private_,
+        WebViewBrowserMessageFilterPrivate::OnDidChangeScrollOffset)
 #if defined(OS_TIZEN)
     IPC_MESSAGE_FORWARD(ViewHostMsg_SnapshotDataReceived, private_,
         WebViewBrowserMessageFilterPrivate::OnSnapshot)
index ab3ead1..a805f07 100644 (file)
       'network_delegate_efl.h',
       'popup_controller_efl.cc',
       'popup_controller_efl.h',
+      'scroll_detector.cc',
+      'scroll_detector.h',
       'selection_box_efl.cc',
       'selection_box_efl.h',
       'selection_controller_efl.cc',
index 41aefc7..e8a229b 100644 (file)
@@ -318,6 +318,8 @@ void EWebView::Initialize() {
 
   selection_controller_.reset(new content::SelectionControllerEfl(this));
 
+  scroll_detector_.reset(new ScrollDetector(this));
+
   web_contents_delegate_.reset(new WebContentsDelegateEfl(this));
   web_contents_->SetDelegate(web_contents_delegate_.get());
   back_forward_list_.reset(new _Ewk_Back_Forward_List(
@@ -1328,47 +1330,33 @@ void EWebView::SetScale(double scale_factor, int x, int y) {
 }
 
 bool EWebView::GetScrollPosition(int* x, int* y) const {
-#if defined(EWK_REFACTOR)
   DCHECK(x);
   DCHECK(y);
-  if (!rwhv()) {
-    *y = *x = 0;
-    return false;
-  }
 
-  if (rwhv()->IsScrollOffsetChanged()) {
+  if (scroll_detector_->IsScrollOffsetChanged()) {
     *x = previous_scroll_position_.x();
     *y = previous_scroll_position_.y();
   } else {
-    const gfx::Vector2d scroll_position = rwhv()->scroll_offset();
+    const gfx::Vector2d scroll_position = scroll_detector_->GetLastScrollPosition();
     *x = scroll_position.x();
     *y = scroll_position.y();
   }
   return true;
-#else
-  NOTIMPLEMENTED();
-  return false;
-#endif
 }
 
 void EWebView::SetScroll(int x, int y) {
-#if defined(EWK_REFACTOR)
   RenderViewHost* render_view_host = web_contents_->GetRenderViewHost();
   if (!render_view_host)
     return;
 
-  if (rwhv()) {
-    rwhv()->SetScrollOffsetChanged();
-    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));
-  }
+  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));
+
+  scroll_detector_->SetScrollOffsetChanged();
 
   render_view_host->Send(new EwkViewMsg_SetScroll(render_view_host->GetRoutingID(), x, y));
-#else
-  NOTIMPLEMENTED();
-#endif
 }
 
 void EWebView::UseSettingsFont() {
index 6f9b2e6..34d4eaa 100644 (file)
@@ -40,6 +40,7 @@
 #include "private/ewk_web_application_icon_data_private.h"
 #include "public/ewk_view.h"
 #include "eweb_view_callbacks.h"
+#include "scroll_detector.h"
 #include "selection_controller_efl.h"
 #include "web_contents_delegate_efl.h"
 #include "context_menu_controller_efl.h"
@@ -327,6 +328,7 @@ class EWebView {
 #ifdef TIZEN_CONTENTS_DETECTION
   content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
 #endif
+  ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
   void SelectRange(const gfx::Point& start, const gfx::Point& end);
   void MoveCaret(const gfx::Point& point);
   void QuerySelectionStyle();
@@ -555,7 +557,7 @@ class EWebView {
   IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
   scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
   content::DevToolsDelegateEfl* inspector_server_;
-
+  scoped_ptr<ScrollDetector> scroll_detector_;
 #if defined(OS_TIZEN_MOBILE)
   content::FileChooserParams::Mode filechooser_mode_;
 #endif
@@ -3,45 +3,46 @@
 // found in the LICENSE file.
 
 #include "eweb_view.h"
-#include "browser/renderer_host/scroll_detector.h"
+#include "scroll_detector.h"
 
-namespace EflWebview {
-
-ScrollDetector::ScrollDetector()
-    : cached_is_main_frame_pinned_to_left_(false),
+ScrollDetector::ScrollDetector(EWebView* web_view)
+    : web_view_(web_view),
+      cached_is_main_frame_pinned_to_left_(false),
       cached_is_main_frame_pinned_to_right_(false),
       cached_is_main_frame_pinned_to_top_(false),
       cached_is_main_frame_pinned_to_bottom_(false),
-      edge_Flag_(false) {
+      edge_Flag_(false),
+      scroll_offset_changed_(false) {
 }
 
-void ScrollDetector::OnChangeScrollOffset(EWebView* web_view,
-    const gfx::Vector2d& scroll_position) {
+void ScrollDetector::OnChangeScrollOffset(const gfx::Vector2d& scroll_position) {
   edge_Flag_ = true;
 
   gfx::Vector2d scroll_delta = scroll_position;
   scroll_delta -= last_scroll_position_;
   last_scroll_position_ = scroll_position;
 
-  DetectEdge(web_view, scroll_delta);
+  DetectEdge(scroll_delta);
 
   if (edge_Flag_ && scroll_delta.x() > 0)
-    web_view->SmartCallback<EWebViewCallbacks::ScrollLeft>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::ScrollLeft>().call();
   if (edge_Flag_ && scroll_delta.x() < 0)
-    web_view->SmartCallback<EWebViewCallbacks::ScrollRight>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::ScrollRight>().call();
   if (edge_Flag_ && scroll_delta.y() < 0)
-    web_view->SmartCallback<EWebViewCallbacks::ScrollDown>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::ScrollDown>().call();
   if (edge_Flag_ && scroll_delta.y() > 0)
-    web_view->SmartCallback<EWebViewCallbacks::ScrollUp>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::ScrollUp>().call();
+
+  scroll_offset_changed_ = false;
 }
 
-void ScrollDetector::DetectEdge(EWebView* web_view, const gfx::Vector2d& scroll_delta) {
+void ScrollDetector::DetectEdge(const gfx::Vector2d& scroll_delta) {
   if (scroll_delta.x()) {
-    CheckForLeftRightEdges(web_view, last_scroll_position_.x());
+    CheckForLeftRightEdges(last_scroll_position_.x());
   }
 
   if (scroll_delta.y()) {
-    CheckForTopBottomEdges(web_view, last_scroll_position_.y());
+    CheckForTopBottomEdges(last_scroll_position_.y());
   }
 }
 
@@ -50,37 +51,35 @@ void ScrollDetector::SetMaxScroll(int x, int y) {
   max_Scroll_.set_y(y);
 }
 
-void ScrollDetector::CheckForLeftRightEdges(EWebView* web_view, int scroll_x) {
+void ScrollDetector::CheckForLeftRightEdges(int scroll_x) {
   bool is_pinned_to_left = scroll_x <= min_Scroll_.x();
   bool is_pinned_to_right = scroll_x >= max_Scroll_.x();
   if (is_pinned_to_left && (is_pinned_to_left != cached_is_main_frame_pinned_to_left_)) {
     edge_Flag_ = false;
-    web_view->SmartCallback<EWebViewCallbacks::EdgeLeft>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::EdgeLeft>().call();
   }
 
   if (is_pinned_to_right && (is_pinned_to_right != cached_is_main_frame_pinned_to_right_)) {
     edge_Flag_ = false;
-    web_view->SmartCallback<EWebViewCallbacks::EdgeRight>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::EdgeRight>().call();
   }
 
   cached_is_main_frame_pinned_to_left_ = is_pinned_to_left;
   cached_is_main_frame_pinned_to_right_ = is_pinned_to_right;
 }
 
-void ScrollDetector::CheckForTopBottomEdges(EWebView* web_view, int scroll_y) {
+void ScrollDetector::CheckForTopBottomEdges(int scroll_y) {
   bool is_pinned_to_top = scroll_y <= min_Scroll_.y();
   bool is_pinned_to_bottom = scroll_y >= max_Scroll_.y();
   if (is_pinned_to_top && (is_pinned_to_top != cached_is_main_frame_pinned_to_top_)) {
     edge_Flag_ = false;
-    web_view->SmartCallback<EWebViewCallbacks::EdgeTop>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::EdgeTop>().call();
   }
 
   if (is_pinned_to_bottom && (is_pinned_to_bottom != cached_is_main_frame_pinned_to_bottom_)) {
     edge_Flag_ = false;
-    web_view->SmartCallback<EWebViewCallbacks::EdgeBottom>().call();
+    web_view_->SmartCallback<EWebViewCallbacks::EdgeBottom>().call();
   }
   cached_is_main_frame_pinned_to_top_ = is_pinned_to_top;
   cached_is_main_frame_pinned_to_bottom_ = is_pinned_to_bottom;
 }
-
-}  // namespace EflWebview
@@ -9,21 +9,21 @@
 
 class EWebView;
 
-namespace EflWebview {
-
 class ScrollDetector {
  public:
-  ScrollDetector();
-  void OnChangeScrollOffset(EWebView* web_view,
-                            const gfx::Vector2d& scroll_position);
+  ScrollDetector(EWebView* web_view);
+  void OnChangeScrollOffset(const gfx::Vector2d& scroll_position);
   void SetMaxScroll(int x, int y);
   gfx::Vector2d GetLastScrollPosition() const { return last_scroll_position_; }
+  bool IsScrollOffsetChanged() const { return scroll_offset_changed_; }
+  void SetScrollOffsetChanged() { scroll_offset_changed_ = true; }
 
  private:
-  void DetectEdge(EWebView* web_view, const gfx::Vector2d& scroll_delta);
-  void CheckForLeftRightEdges(EWebView* web_view, int scroll_x);
-  void CheckForTopBottomEdges(EWebView* web_view, int sroll_y);
+  void DetectEdge(const gfx::Vector2d& scroll_delta);
+  void CheckForLeftRightEdges(int scroll_x);
+  void CheckForTopBottomEdges(int sroll_y);
 
+  EWebView* web_view_;
   gfx::Vector2d last_scroll_position_;
   gfx::Vector2d max_Scroll_;
   gfx::Vector2d min_Scroll_;
@@ -32,8 +32,7 @@ class ScrollDetector {
   bool cached_is_main_frame_pinned_to_top_;
   bool cached_is_main_frame_pinned_to_bottom_;
   bool edge_Flag_;
+  bool scroll_offset_changed_;
 };
 
-}  // namespace EflWebview
-
 #endif //_SCROLL_DETECTOR_H