Merge "[dali-toolkit]: add texteditor scrolling functionality" into devel/master
authorjoogab yun <joogab.yun@samsung.com>
Fri, 30 Oct 2020 07:36:19 +0000 (07:36 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 30 Oct 2020 07:36:19 +0000 (07:36 +0000)
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h

index b6f3da8..49e630d 100644 (file)
@@ -3084,3 +3084,50 @@ int UtcDaliTextEditorEnableEditing(void)
 
   END_TEST;
 }
+
+int UtcDaliTextEditorScrolling(void)
+{
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextEditorScrolling ");
+
+  TextEditor textEditor = TextEditor::New();
+  DALI_TEST_CHECK( textEditor );
+
+  application.GetScene().Add( textEditor );
+
+  // Avoid a crash when core load gl resources.
+  application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE );
+
+  application.SendNotification();
+  application.Render();
+
+  textEditor.SetProperty(TextEditor::Property::TEXT, "Tex1\nTex2\nTex3\nTex4\nTex5\nTex6\nTex7\nTex8");
+  textEditor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
+  textEditor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
+  textEditor.SetProperty(Actor::Property::SIZE, Vector2(60.0f, 160.0f));
+
+  application.SendNotification();
+  application.Render();
+
+  DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get<float>(), 0.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get<float>(), 0.0f, TEST_LOCATION );
+
+
+  DevelTextEditor::ScrollBy(textEditor, Vector2(1.0f, 1.0f));
+
+  DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get<float>(), 1.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get<float>(), 0.0f, TEST_LOCATION );
+
+  DevelTextEditor::ScrollBy(textEditor, Vector2(0.0f, 1000.0f));
+
+  DALI_TEST_NOT_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get<float>(), 1.0f, 0.1f, TEST_LOCATION );
+  DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get<float>(), 0.0f, TEST_LOCATION );
+
+  textEditor.SetProperty(DevelTextEditor::Property::VERTICAL_SCROLL_POSITION , 0.0f);
+  textEditor.SetProperty(DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION , 0.0f);
+
+  DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::VERTICAL_SCROLL_POSITION ).Get<float>(), 0.0f, TEST_LOCATION );
+  DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION ).Get<float>(), 0.0f, TEST_LOCATION );
+
+  END_TEST;
+}
index adcff4c..abe3389 100644 (file)
@@ -45,6 +45,11 @@ void SelectNone(TextEditor textEditor)
   GetImpl(textEditor).SelectNone();
 }
 
+void ScrollBy(TextEditor textEditor, Vector2 scroll)
+{
+  GetImpl(textEditor).ScrollBy(scroll);
+}
+
 } // namespace DevelTextEditor
 
 } // namespace Toolkit
index 0db66e5..6cb473c 100644 (file)
@@ -140,6 +140,18 @@ enum Type
   SELECTED_TEXT_END,
 
   /**
+   * @brief The horizontal scroll position in pixels.
+   * @details Name "horizontalScrollPosition", type Property::FLOAT.
+   */
+  HORIZONTAL_SCROLL_POSITION,
+
+  /**
+   * @brief The vertical scroll position in pixels.
+   * @details Name "verticalScrollPosition", type Property::FLOAT.
+   */
+  VERTICAL_SCROLL_POSITION,
+
+  /**
    * @brief The Editable state of control.
    * @details Name "enableEditing", type Property::BOOLEAN.
    */
@@ -194,6 +206,14 @@ DALI_TOOLKIT_API void SelectWholeText(TextEditor textEditor);
  */
 DALI_TOOLKIT_API void SelectNone(TextEditor textEditor);
 
+/**
+ * @brief Scroll the TextEditor by specific amount.
+ *
+ * @param[in] textEditor The instance of TextEditor.
+ * @param[in] scroll amount (in pixels) of scrolling in horizontal & vectical directions.
+ */
+DALI_TOOLKIT_API void ScrollBy(TextEditor textEditor, Vector2 scroll);
+
 } // namespace DevelTextEditor
 
 } // namespace Toolkit
index 60db674..75f6d6f 100644 (file)
@@ -142,6 +142,8 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend",
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength",                      INTEGER,   MAX_LENGTH                           )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextStart",              INTEGER,   SELECTED_TEXT_START                  )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "selectedTextEnd",                INTEGER,   SELECTED_TEXT_END                    )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "horizontalScrollPosition",       FLOAT,     HORIZONTAL_SCROLL_POSITION           )
+DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "verticalScrollPosition",         INTEGER,   VERTICAL_SCROLL_POSITION             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableEditing",                  BOOLEAN,   ENABLE_EDITING                       )
 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "selectedText",         STRING,    SELECTED_TEXT                        )
 
@@ -721,6 +723,26 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P
         impl.SetEditable( editable );
         break;
       }
+      case Toolkit::DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION:
+      {
+        float horizontalScroll = value.Get< float >();
+        DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p HORIZONTAL_SCROLL_POSITION %d\n", impl.mController.Get(), horizontalScroll );
+        if (horizontalScroll >= 0.0f)
+        {
+          impl.ScrollBy( Vector2(horizontalScroll - impl.GetHorizontalScrollPosition(), 0 ));
+        }
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::VERTICAL_SCROLL_POSITION:
+      {
+        float verticalScroll = value.Get< float >();
+        DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p VERTICAL_SCROLL_POSITION %d\n", impl.mController.Get(), verticalScroll );
+        if (verticalScroll >= 0.0f)
+        {
+          impl.ScrollBy( Vector2(0, verticalScroll - impl.GetVerticalScrollPosition() ));
+        }
+        break;
+      }
     } // switch
   } // texteditor
 }
@@ -1057,6 +1079,16 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind
         value = impl.IsEditable();
         break;
       }
+      case Toolkit::DevelTextEditor::Property::HORIZONTAL_SCROLL_POSITION:
+      {
+        value = impl.GetHorizontalScrollPosition();
+        break;
+      }
+      case Toolkit::DevelTextEditor::Property::VERTICAL_SCROLL_POSITION:
+      {
+        value = impl.GetVerticalScrollPosition();
+        break;
+      }
     } //switch
   }
 
@@ -1080,6 +1112,32 @@ void TextEditor::SelectNone()
   }
 }
 
+void TextEditor::ScrollBy(Vector2 scroll)
+{
+  if( mController && mController->IsShowingRealText() )
+  {
+    mController->ScrollBy(scroll);
+  }
+}
+
+float TextEditor::GetHorizontalScrollPosition()
+{
+  if( mController && mController->IsShowingRealText() )
+  {
+    return mController->GetHorizontalScrollPosition();
+  }
+  return 0;
+}
+
+float TextEditor::GetVerticalScrollPosition()
+{
+  if( mController && mController->IsShowingRealText() )
+  {
+    return mController->GetVerticalScrollPosition();
+  }
+  return 0;
+}
+
 string TextEditor::GetSelectedText() const
 {
   string selectedText = "";
index 2aca941..0cb7204 100755 (executable)
@@ -226,6 +226,25 @@ public:
   void SelectNone() override;
 
   /**
+   * @copydoc Dali::Toolkit::DevelTextEditor::ScrollBy()
+   */
+  void ScrollBy(Vector2 Scroll);
+
+  /**
+   * @brief Get Horizontal scroll position of TextEditor.
+   *
+   * @return Horizontal scroll position (in pixels) of TextEditor.
+   */
+  float GetHorizontalScrollPosition();
+
+  /**
+   * @brief Get Vertical scroll position of TextEditor.
+   *
+   * @return Vertical scroll position (in pixels) of TextEditor.
+   */
+  float GetVerticalScrollPosition();
+
+  /**
    * @copydoc Text::SelectableControlInterface::GetSelectedText()
    */
   string GetSelectedText() const override;
index 31c1edf..6fe0d0c 100755 (executable)
@@ -2239,6 +2239,56 @@ void Controller::SetEditable( bool editable )
   }
 }
 
+void Controller::ScrollBy( Vector2 scroll )
+{
+  if( mImpl->mEventData && (fabs(scroll.x) > Math::MACHINE_EPSILON_0 || fabs(scroll.y) > Math::MACHINE_EPSILON_0))
+  {
+      const Vector2& layoutSize = mImpl->mModel->mVisualModel->GetLayoutSize();
+      const Vector2 currentScroll = mImpl->mModel->mScrollPosition;
+
+      scroll.x = -scroll.x;
+      scroll.y = -scroll.y;
+
+      if( fabs(scroll.x) > Math::MACHINE_EPSILON_0 )
+      {
+        mImpl->mModel->mScrollPosition.x += scroll.x;
+        mImpl->ClampHorizontalScroll( layoutSize );
+      }
+
+      if( fabs(scroll.y) > Math::MACHINE_EPSILON_0 )
+      {
+        mImpl->mModel->mScrollPosition.y += scroll.y;
+        mImpl->ClampVerticalScroll( layoutSize );
+      }
+
+      if (mImpl->mModel->mScrollPosition != currentScroll)
+      {
+        mImpl->mEventData->mDecorator->UpdatePositions( mImpl->mModel->mScrollPosition - currentScroll );
+        mImpl->RequestRelayout();
+      }
+  }
+}
+
+float Controller::GetHorizontalScrollPosition()
+{
+  if( mImpl->mEventData )
+  {
+    //scroll values are negative internally so we convert them to positive numbers
+    return -mImpl->mModel->mScrollPosition.x;
+  }
+  return 0;
+}
+
+float Controller::GetVerticalScrollPosition()
+{
+  if( mImpl->mEventData )
+  {
+    //scroll values are negative internally so we convert them to positive numbers
+    return -mImpl->mModel->mScrollPosition.y;
+  }
+  return 0;
+}
+
 void Controller::DecorationEvent( HandleType handleType, HandleState state, float x, float y )
 {
   EventHandler::DecorationEvent(*this, handleType, state, x, y);
index 54444b1..6bd8706 100755 (executable)
@@ -1531,6 +1531,21 @@ public: // Text-input Event Queuing.
   virtual void SetEditable( bool editable );
 
   /**
+   * @copydoc Dali::Toolkit::Internal::TextEditor::ScrollBy()
+   */
+  virtual void ScrollBy( Vector2 scroll );
+
+  /**
+   * @copydoc Dali::Toolkit::Internal::TextEditor::GetHorizontalScrollPosition()
+   */
+  float GetHorizontalScrollPosition();
+
+  /**
+   * @copydoc Dali::Toolkit::Internal::TextEditor::GetVerticalScrollPosition()
+   */
+  float GetVerticalScrollPosition();
+
+  /**
    * @brief Event received from input method context
    *
    * @param[in] inputMethodContext The input method context.