Simplify SelectionControllerEfl state machine: eliminate "caret selection" setter
authorAntonio Gomes <a1.gomes@samsung.com>
Fri, 30 Oct 2015 18:10:14 +0000 (14:10 -0400)
committerYoungsoo Choi <kenshin.choi@samsung.com>
Tue, 10 Jul 2018 07:55:23 +0000 (07:55 +0000)
Our text selection implementation works similar to a state
machine with the following states, to mention some:
- enabled on/off;
- caret selection on/off
- editable selecton on/off
- etc

Specifially about the "caret" selection "state", although it is
possible to set it on and off manually today, it should only be
set by the selection controller in one specific case: start and end
selections are equal, and focused node is content editable.

Based on that, patch simplifies the logic that sets this state,
without cause behavior changes.

Additionally some member variables from SelectionBoxEfl class are
removed: editable_ (redudant) and is_caret_selection_ (unneeded).

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

Reviewed by: a.renevier, djmix.kim, sns.park

Change-Id: Ib8fa1ca2efab23944b1d0777db776d46a40d0ab6
Signed-off-by: Antonio Gomes <a1.gomes@samsung.com>
tizen_src/chromium_impl/content/browser/renderer_host/render_widget_host_view_efl.cc
tizen_src/chromium_impl/content/browser/selection/selection_box_efl.cc
tizen_src/chromium_impl/content/browser/selection/selection_box_efl.h
tizen_src/chromium_impl/content/browser/selection/selection_controller_efl.cc
tizen_src/chromium_impl/content/browser/selection/selection_controller_efl.h

index 3643f91..25e34f3 100755 (executable)
@@ -892,17 +892,14 @@ void RenderWidgetHostViewEfl::ImeCompositionRangeChanged(
   const gfx::Range& range,
   const std::vector<gfx::Rect>& character_bounds) {
 
-  if (GetSelectionController()) {
-    GetSelectionController()->SetCaretSelectionStatus(false);
+  if (GetSelectionController())
     GetSelectionController()->HideHandleAndContextMenu();
-  }
 }
 
 void RenderWidgetHostViewEfl::FocusedNodeChanged(bool is_editable_node) {
-  if (GetSelectionController()) {
-    GetSelectionController()->SetCaretSelectionStatus(false);
+  if (GetSelectionController())
     GetSelectionController()->HideHandleAndContextMenu();
-  }
+
   if (im_context_ && im_context_->IsShow() &&
     ClipboardHelperEfl::GetInstance()->IsClipboardWindowOpened()) {
     ClipboardHelperEfl::GetInstance()->CloseClipboardWindow();
index e12b92b..f912866 100644 (file)
@@ -10,8 +10,6 @@ namespace content {
 
 SelectionBoxEfl::SelectionBoxEfl(Evas_Object* parent_view)
   : status_(false),
-    editable_(false),
-    is_caret_selection_(false),
     is_anchor_first_(false),
     context_params_(new ContextMenuParams()),
     parent_view_(parent_view) {
@@ -52,7 +50,7 @@ bool SelectionBoxEfl::UpdateRectData(const gfx::Rect& left_rect, const gfx::Rect
 }
 
 bool SelectionBoxEfl::IsInEditField() const {
-  return (editable_ && !(left_rect_.width() && !(left_rect_.height())));
+  return (GetEditable() && !(left_rect_.width() && !(left_rect_.height())));
 }
 
 void SelectionBoxEfl::SetStatus(bool enable) {
index 799531c..022b4db 100644 (file)
@@ -26,15 +26,13 @@ class SelectionBoxEfl {
 
   void SetStatus(bool enable);
   bool GetStatus() const { return status_; }
-  void SetEditable(bool enable) { GetContextMenuParams()->is_editable = editable_ = enable; }
-  bool GetEditable() const { return editable_; }
+  void SetEditable(bool enable) { GetContextMenuParams()->is_editable = enable; }
+  bool GetEditable() const { return GetContextMenuParams()->is_editable; }
   void UpdateSelectStringData(const base::string16& text);
   // Returns true if the rectangle is changed.
   bool UpdateRectData(const gfx::Rect& left_rect, const gfx::Rect& right_rect);
   void ClearRectData();
   bool IsInEditField() const;
-  void SetCaretSelectionStatus(const bool enable) { is_caret_selection_ = enable; }
-  bool GetCaretSelectionStatus() const { return is_caret_selection_; }
   gfx::Rect GetLeftRect() const { return left_rect_; }
   gfx::Rect GetRightRect() const { return right_rect_; }
   void SetIsAnchorFirst(bool value) { is_anchor_first_ = value; }
@@ -45,12 +43,6 @@ class SelectionBoxEfl {
   // Save the state of selection, if active or not
   bool status_;
 
-  // Save if the selection is in one of the editable fields
-  bool editable_;
-
-  // Caret is in a input field
-  bool is_caret_selection_;
-
   // Start of selection
   gfx::Rect left_rect_;
 
index dd2d275..ae20894 100644 (file)
@@ -51,7 +51,8 @@ SelectionControllerEfl::SelectionControllerEfl(Evas_Object* parent_view, WebCont
        is_selection_visible_(false),
        show_only_large_handle_(false),
        handle_being_dragged_(false),
-       web_contents_(web_contents) {
+       web_contents_(web_contents),
+       selection_mode_(None) {
   evas_object_event_callback_add(parent_view_, EVAS_CALLBACK_MOVE, &EvasParentViewMoveCallback, this);
 
 #if defined(OS_TIZEN)
@@ -97,15 +98,10 @@ bool SelectionControllerEfl::GetSelectionEditable() const {
   return selection_data_->GetEditable();
 }
 
-void SelectionControllerEfl::SetCaretSelectionStatus(const bool enable) {
-  TRACE_EVENT1("selection,efl", __PRETTY_FUNCTION__, "caret selection", enable);
-  selection_data_->SetCaretSelectionStatus(enable);
-}
-
 bool SelectionControllerEfl::GetCaretSelectionStatus() const {
   TRACE_EVENT1("selection,efl", __PRETTY_FUNCTION__,
-               "caret selection", selection_data_->GetCaretSelectionStatus());
-  return selection_data_->GetCaretSelectionStatus();
+               "caret selection", selection_mode_ == Caret);
+  return selection_mode_ == Caret;
 }
 
 void SelectionControllerEfl::SetScrollStatus(const bool enable) {
@@ -167,10 +163,29 @@ bool SelectionControllerEfl::ClearSelectionViaEWebView() {
   return false;
 }
 
+void SelectionControllerEfl::SetSelectionMode(enum SelectionMode mode) {
+  selection_mode_ = mode;
+}
+
+void SelectionControllerEfl::DetermineSelectionMode(
+    const gfx::Rect& left_rect,
+    const gfx::Rect& right_rect) {
+
+  if (left_rect == gfx::Rect() && right_rect == gfx::Rect())
+    SetSelectionMode(None);
+  else if (left_rect == right_rect && GetSelectionEditable())
+    SetSelectionMode(Caret);
+  else
+    SetSelectionMode(Range);
+}
+
 bool SelectionControllerEfl::UpdateSelectionDataAndShow(
     const gfx::Rect& left_rect,
     const gfx::Rect& right_rect,
     bool show) {
+
+  DetermineSelectionMode(left_rect, right_rect);
+
   TRACE_EVENT0("selection,efl", __PRETTY_FUNCTION__);
   if (!show && !IsSelectionValid(left_rect, right_rect)) {
     if (!GetCaretSelectionStatus())
@@ -232,7 +247,7 @@ void SelectionControllerEfl::ShowHandleAndContextMenuIfRequired() {
     }
 
     gfx::Rect left = selection_data_->GetLeftRect();
-    if (selection_data_->GetCaretSelectionStatus()) {
+    if (GetCaretSelectionStatus()) {
       input_handle_->SetBasePosition(gfx::Point(left.x(), left.y()));
       input_handle_->Move(left.bottom_right());
       input_handle_->Show();
@@ -348,7 +363,6 @@ void SelectionControllerEfl::CancelContextMenu(int request_id) {
 }
 
 void SelectionControllerEfl::HideHandles() {
-  SetCaretSelectionStatus(false);
   Clear();
 }
 
@@ -616,8 +630,6 @@ bool SelectionControllerEfl::HandleLongPressEvent(
 void SelectionControllerEfl::HandleLongPressEventPrivate(const gfx::Point& touch_point) {
   show_only_large_handle_ = false;
   Clear();
-  if (selection_data_->IsInEditField())
-    SetCaretSelectionStatus(true);
 
   Evas_Coord x, y;
   evas_object_geometry_get(parent_view_, &x, &y, 0, 0);
@@ -635,7 +647,6 @@ void SelectionControllerEfl::HandleLongPressMoveEvent(const gfx::Point& touch_po
     if (rwhv)
       rwhv->MoveCaret(gfx::Point(touch_point.x() - x, touch_point.y() - y));
     SetSelectionStatus(true);
-    SetCaretSelectionStatus(true);
   } else{
     if (rwhv)
       rwhv->SelectClosestWord(touch_point);
@@ -647,7 +658,7 @@ void SelectionControllerEfl::HandleLongPressEndEvent() {
   long_mouse_press_ = false;
   if (scrolling_)
     show_after_scroll_ = true;
-  if (selection_data_->GetCaretSelectionStatus()) {
+  if (GetCaretSelectionStatus()) {
     SetSelectionStatus(true);
     SetSelectionEditable(true);
   }
@@ -659,7 +670,6 @@ void SelectionControllerEfl::PostHandleTapGesture(bool is_content_editable) {
     DVLOG(1) << "DispatchPostponedGestureEvent :: Editable";
     SetSelectionStatus(true);
     if (GetSelectionEditable()){
-      SetCaretSelectionStatus(true);
       UpdateSelectionDataAndShow(
           GetLeftRect(), GetRightRect(), false);
     } else {
@@ -667,7 +677,6 @@ void SelectionControllerEfl::PostHandleTapGesture(bool is_content_editable) {
     }
   } else {
     SetSelectionEditable(false);
-    SetCaretSelectionStatus(false);
   }
 }
 
@@ -699,12 +708,6 @@ bool SelectionControllerEfl::IsSelectionValid(const gfx::Rect& left_rect,
   if (!GetSelectionStatus())
     SetSelectionStatus(true);
 
-  if ((left_rect.x() != right_rect.x() || left_rect.y() != right_rect.y()) &&
-      selection_data_->IsInEditField() && GetCaretSelectionStatus()) {
-    if (!long_mouse_press_)
-      SetCaretSelectionStatus(false);
-  }
-
   return true;
 }
 
@@ -713,7 +716,7 @@ void SelectionControllerEfl::ClearSelection() {
   Clear();
   selection_data_->SetStatus(false);
   SetSelectionEditable(false);
-  SetCaretSelectionStatus(false);
+  SetSelectionMode(None);
 }
 
 void SelectionControllerEfl::OnParentParentViewMove() {
index 97c6647..7d8fd9b 100644 (file)
@@ -61,10 +61,13 @@ class CONTENT_EXPORT SelectionControllerEfl {
   // Set if selection is valid
   void SetSelectionStatus(bool enable);
   bool GetSelectionStatus() const;
+
   // Set if selection is in edit field
   void SetSelectionEditable(bool enable);
   bool GetSelectionEditable() const;
 
+  bool GetCaretSelectionStatus() const;
+
   // Set if the selection base (or anchor) comes logically
   // first than its respective extent.
   void SetIsAnchorFirst(bool value);
@@ -83,9 +86,6 @@ class CONTENT_EXPORT SelectionControllerEfl {
   void HandleDragUpdateNotification(SelectionHandleEfl*);
   void HandleDragEndNotification();
 
-  void SetCaretSelectionStatus(const bool enable);
-  bool GetCaretSelectionStatus() const;
-
   // Clears the selection and hides context menu and handles
   void ClearSelection();
   bool ClearSelectionViaEWebView();
@@ -126,6 +126,14 @@ class CONTENT_EXPORT SelectionControllerEfl {
   void HandleGestureEnd();
 
  private:
+  enum SelectionMode {
+    None = 0,
+    Caret,
+    Range
+  };
+  void DetermineSelectionMode(const gfx::Rect& left_rect, const gfx::Rect& right_rect);
+  void SetSelectionMode(enum SelectionMode);
+
   void HandleLongPressEventPrivate(const gfx::Point& touch_point);
 
   void ShowHandleAndContextMenuIfRequired();
@@ -208,6 +216,7 @@ class CONTENT_EXPORT SelectionControllerEfl {
 
   WebContents& web_contents_;
 
+  enum SelectionMode selection_mode_;
   ui::SelectionBound start_selection_;
   ui::SelectionBound end_selection_;
 };