Simplify SelectionControllerEfl::OnMouseMove
authorAntonio Gomes <a1.gomes@samsung.com>
Wed, 19 Aug 2015 15:18:45 +0000 (11:18 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 06:57:09 +0000 (06:57 +0000)
By passing the SelectionHandleEfl object as a parameter
instead of its type, we can greatly simplify this method.

For instance, patch factors out the magnifier positioning
logic out of the switch, now that it is common for all 3
types of handles.

Additionally, now two cases in the 'switch' statement can be
colapsed (ones that handle HANDLE_TYPE_LEFT and RIGHT).

Last, patch also moves the declaration of the
local variables within the scope they are needed.

Original beta/m42 patch:
- http://165.213.202.130/gerrit/#/c/85428/ , reviewed by
Janusz Majnert, Arnaud Renevier.

Bug: http://107.108.218.239/bugzilla/show_bug.cgi?id=14304

Reviewed by: Janusz Majnert

Change-Id: Ie1b8a105e155e54e33e267d1ba70243a57234bd5
Signed-off-by: Antonio Gomes <a1.gomes@samsung.com>
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_handle_efl.cc
tizen_src/chromium_impl/content/browser/selection/selection_handle_efl.h

index 71d3c28..2fbe86a 100644 (file)
@@ -415,59 +415,45 @@ void SelectionControllerEfl::OnMouseDown(
 
   magnifier_->UpdateLocation(magnifier_point);
   magnifier_->Move(magnifier_point);
-
   magnifier_->Show();
   ShowHandleAndContextMenuIfRequired();
 }
 
 void SelectionControllerEfl::OnMouseMove(const gfx::Point& touch_point,
-    SelectionHandleEfl::HandleType handle) {
+    SelectionHandleEfl* handle) {
   show_only_large_handle_ = false;
   // FIXME : Check the text Direction later
   Evas_Coord x, y;
   evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
   expecting_update_ = true;
+
   gfx::Point magnifier_point;
-  gfx::Point start_point, end_point;
-  WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
-  RenderWidgetHostViewEfl* rwhv =
-      static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
-  float device_scale_factor =
-      gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
-
-  switch (handle) {
-    case SelectionHandleEfl::HANDLE_TYPE_INPUT:
-      magnifier_point.set_x(input_handle_->GetBasePosition().x() + x);
-      magnifier_point.set_y(input_handle_->GetBasePosition().y() + y);
-      magnifier_->UpdateLocation(magnifier_point);
-      magnifier_->Move(magnifier_point);
+  magnifier_point.set_x(handle->GetBasePosition().x() + x);
+  magnifier_point.set_y(handle->GetBasePosition().y() + y);
+  magnifier_->UpdateLocation(magnifier_point);
+  magnifier_->Move(magnifier_point);
+
+  switch (handle->Type()) {
+    case SelectionHandleEfl::HANDLE_TYPE_INPUT: {
+      RenderWidgetHostViewEfl* rwhv =
+          static_cast<RenderWidgetHostViewEfl*>(web_contents_.GetRenderWidgetHostView());
       if (rwhv)
-        rwhv->MoveCaret(input_handle_->GetBasePosition());
+        rwhv->MoveCaret(handle->GetBasePosition());
       return;
+    }
     case SelectionHandleEfl::HANDLE_TYPE_LEFT:
-      magnifier_point.set_x(start_handle_->GetBasePosition().x() + x);
-      magnifier_point.set_y(start_handle_->GetBasePosition().y() + y);
-      magnifier_->UpdateLocation(magnifier_point);
-      magnifier_->Move(magnifier_point);
-
-      start_point.set_x(start_handle_->GetBasePosition().x() / device_scale_factor);
-      start_point.set_y(start_handle_->GetBasePosition().y() / device_scale_factor);
-      end_point.set_x(end_handle_->GetBasePosition().x() / device_scale_factor);
-      end_point.set_y(end_handle_->GetBasePosition().y() / device_scale_factor);
-      wci->SelectRange(start_point, end_point);
-      return;
-    case SelectionHandleEfl::HANDLE_TYPE_RIGHT:
-      magnifier_point.set_x(end_handle_->GetBasePosition().x() + x);
-      magnifier_point.set_y(end_handle_->GetBasePosition().y() + y);
-      magnifier_->UpdateLocation(magnifier_point);
-      magnifier_->Move(magnifier_point);
-
+    case SelectionHandleEfl::HANDLE_TYPE_RIGHT: {
+      gfx::Point start_point, end_point;
+      float device_scale_factor =
+          gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().device_scale_factor();
       start_point.set_x(start_handle_->GetBasePosition().x() / device_scale_factor);
       start_point.set_y(start_handle_->GetBasePosition().y() / device_scale_factor);
       end_point.set_x(end_handle_->GetBasePosition().x() / device_scale_factor);
       end_point.set_y(end_handle_->GetBasePosition().y() / device_scale_factor);
+      WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
       wci->SelectRange(start_point, end_point);
       return;
+    }
   }
 }
 
index 1fe3713..b631a4a 100644 (file)
@@ -78,7 +78,7 @@ class CONTENT_EXPORT SelectionControllerEfl {
   void GetSelectionBounds(gfx::Rect* left, gfx::Rect* right);
   // Handles the mouse press,move and relase events on selection handles
   void OnMouseDown(const gfx::Point& touch_point, SelectionHandleEfl*);
-  void OnMouseMove(const gfx::Point& touch_point, SelectionHandleEfl::HandleType);
+  void OnMouseMove(const gfx::Point& touch_point, SelectionHandleEfl*);
   void OnMouseUp(const gfx::Point& touch_point);
 
   void SetCaretSelectionStatus(const bool enable);
index faaa33c..038d1f2 100644 (file)
@@ -134,7 +134,7 @@ void SelectionHandleEfl::UpdateMouseMove(void* data) {
   handle->base_point_.SetPoint(delta_x, delta_y);
   handle->controller_.OnMouseMove(
       gfx::Point(handle->current_touch_point_.x(),
-                 handle->current_touch_point_.y()), handle->handle_type_);
+                 handle->current_touch_point_.y()), handle);
 }
 
 SelectionHandleEfl::HandleDirection SelectionHandleEfl::CalculateDirection(
index 3b8a766..79d057c 100644 (file)
@@ -52,6 +52,8 @@ class SelectionHandleEfl {
   bool IsTop() { return is_top_; }
   Evas_Object* evas_object() const { return handle_; }
 
+  HandleType Type() const { return handle_type_; }
+
  private:
   static void OnMouseDown(void* data, Evas*, Evas_Object*, void* event_info);
   static void OnMouseMove(void* data, Evas*, Evas_Object*, void* event_info);