Added ScrollStateChangedSignal to TextEditor. 92/132092/10
authorminho.sun <minho.sun@samsung.com>
Thu, 1 Jun 2017 05:22:22 +0000 (14:22 +0900)
committerminho.sun <minho.sun@samsung.com>
Thu, 8 Jun 2017 12:55:14 +0000 (21:55 +0900)
Added ScrollStateChagnedSignal to TextEditor.

State : STARTED / FINISHED

When UpdateScrollBar() called, STARTED.
When ScrollBar indicator animation is stopped, FINISHED.

Change-Id: I66409fee2432958aa17b49c4f8025f93a010403f
Signed-off-by: minho.sun <minho.sun@samsung.com>
automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp [new file with mode: 0644]
dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h
dali-toolkit/devel-api/file.list
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-editor-impl.h

index 9fd6789..c143510 100644 (file)
@@ -18,7 +18,6 @@
 #include <iostream>
 #include <stdlib.h>
 #include <unistd.h>
-
 #include <dali/public-api/rendering/renderer.h>
 #include <dali/devel-api/adaptor-framework/clipboard.h>
 #include <dali/integration-api/events/key-event-integ.h>
@@ -299,6 +298,31 @@ bool DaliTestCheckMaps( const Property::Map& fontStyleMapGet, const Property::Ma
   return true;
 }
 
+class ScrollStateChangeCallback : public Dali::ConnectionTracker
+{
+public:
+  ScrollStateChangeCallback(bool& startedCalled, bool& finishedCalled)
+  : mStartedCalled( startedCalled ),
+    mFinishedCalled( finishedCalled )
+  {
+  }
+
+  void Callback( TextEditor editor, DevelTextEditor::Scroll::Type type )
+  {
+    if( type == DevelTextEditor::Scroll::STARTED )
+    {
+      mStartedCalled = true;
+    }
+    else if( type == DevelTextEditor::Scroll::FINISHED )
+    {
+      mFinishedCalled = true;
+    }
+  }
+
+  bool& mStartedCalled;
+  bool& mFinishedCalled;
+};
+
 } // namespace
 
 int UtcDaliToolkitTextEditorConstructorP(void)
@@ -1957,6 +1981,7 @@ int utcDaliTextEditorFontStylePropertyStringP(void)
 
   END_TEST;
 }
+
 int utcDaliTextEditorGetPropertyLinecountP(void)
 {
   ToolkitTestApplication application;
@@ -1982,3 +2007,44 @@ int utcDaliTextEditorGetPropertyLinecountP(void)
 
   END_TEST;
 }
+
+int utcDaliTextEditorScrollStateChangedSignalTest(void)
+{
+
+  ToolkitTestApplication application;
+  tet_infoline(" UtcDaliTextEditorScrollStateChangedSignalTest");
+
+  TextEditor editor = TextEditor::New();
+  DALI_TEST_CHECK( editor );
+
+  Stage::GetCurrent().Add( editor );
+
+  editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f );
+  editor.SetSize( 50.f, 50.f );
+  editor.SetParentOrigin( ParentOrigin::TOP_LEFT );
+  editor.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  editor.SetProperty( DevelTextEditor::Property::ENABLE_SCROLL_BAR, true );
+  editor.SetKeyboardFocusable(true);
+
+  bool startedCalled = false;
+  bool finishedCalled = false;
+
+  ScrollStateChangeCallback callback( startedCalled, finishedCalled );
+  DevelTextEditor::ScrollStateChangedSignal( editor ).Connect( &callback, &ScrollStateChangeCallback::Callback );
+
+  KeyboardFocusManager::Get().SetCurrentFocusActor( editor );
+
+  // Render and notify
+  application.SendNotification();
+  application.Render();
+
+  editor.SetProperty( TextEditor::Property::TEXT, "Long enough message for TextEditor!");
+  application.SendNotification();
+  application.Render(6000);
+
+  application.SendNotification();
+  DALI_TEST_EQUALS( startedCalled, true, TEST_LOCATION );
+  DALI_TEST_EQUALS( finishedCalled, true, TEST_LOCATION );
+
+  END_TEST;
+}
diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp
new file mode 100644 (file)
index 0000000..e9292bf
--- /dev/null
@@ -0,0 +1,43 @@
+
+/*
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
+
+// INTERNAL HEADER
+#include <dali-toolkit/internal/controls/text-controls/text-editor-impl.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace DevelTextEditor
+{
+
+ScrollStateChangedSignalType& ScrollStateChangedSignal( TextEditor textEditor )
+{
+  return Dali::Toolkit::GetImpl( textEditor ).ScrollStateChangedSignal();
+}
+
+} // namespace DevelText
+
+} // namespace Toolkit
+
+} // namespace Dali
index 473adba..f95fc94 100644 (file)
@@ -132,7 +132,30 @@ namespace Property
   };
 } // namespace Property
 
-} // namespace DevelText
+namespace Scroll
+{
+  enum Type
+  {
+    STARTED,   ///< Scrolling is started.
+    FINISHED   ///< Scrolling is finished.
+  };
+} // namespace Scroll
+
+typedef Signal< void ( TextEditor, Scroll::Type ) > ScrollStateChangedSignalType;
+
+/**
+ * @brief This signal is emitted when TextEditor scrolling is started or finished.
+ *
+ * A callback of the following type may be connected:
+ * @code
+ *   void YourCallbackName( ScrollState::Type type );
+ * @endcode
+ * type: Whether the scrolling is started or finished.
+ * @return The signal to connect to
+ */
+DALI_IMPORT_API ScrollStateChangedSignalType& ScrollStateChangedSignal( TextEditor textEditor );
+
+} // namespace DevelTextEditor
 
 } // namespace Toolkit
 
index fa85816..fe8ef2b 100644 (file)
@@ -23,6 +23,7 @@ devel_api_src_files = \
   $(devel_api_src_dir)/controls/super-blur-view/super-blur-view.cpp \
   $(devel_api_src_dir)/controls/text-controls/text-selection-popup.cpp \
   $(devel_api_src_dir)/controls/text-controls/text-selection-toolbar.cpp \
+  $(devel_api_src_dir)/controls/text-controls/text-editor-devel.cpp \
   $(devel_api_src_dir)/controls/tool-bar/tool-bar.cpp \
   $(devel_api_src_dir)/focus-manager/keyinput-focus-manager.cpp \
   $(devel_api_src_dir)/focus-manager/keyboard-focus-manager-devel.cpp \
index ca78a26..1a918cd 100644 (file)
@@ -1091,6 +1091,11 @@ Toolkit::TextEditor::InputStyleChangedSignalType& TextEditor::InputStyleChangedS
   return mInputStyleChangedSignal;
 }
 
+Toolkit::DevelTextEditor::ScrollStateChangedSignalType& TextEditor::ScrollStateChangedSignal()
+{
+  return mScrollStateChangedSignal;
+}
+
 void TextEditor::OnInitialize()
 {
   Actor self = Self();
@@ -1495,6 +1500,14 @@ void TextEditor::UpdateScrollBar()
     return;
   }
 
+  // If scrolling is not started, start scrolling and emit ScrollStateChangedSignal
+  if( !mScrollStarted )
+  {
+    mScrollStarted = true;
+    Dali::Toolkit::TextEditor handle( GetOwner() );
+    mScrollStateChangedSignal.Emit( handle, DevelTextEditor::Scroll::STARTED );
+  }
+
   CustomActor self = Self();
   if( !mScrollBar )
   {
@@ -1550,6 +1563,18 @@ void TextEditor::UpdateScrollBar()
   indicator.SetOpacity(1.0f);
   mAnimation.AnimateTo( Property( indicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN, mAnimationPeriod );
   mAnimation.Play();
+  mAnimation.FinishedSignal().Connect( this, &TextEditor::OnScrollIndicatorAnimationFinished );
+}
+
+void TextEditor::OnScrollIndicatorAnimationFinished( Animation& animation )
+{
+  // If animation is successfully ended, then emit ScrollStateChangedSignal
+  if( animation.GetCurrentProgress() == 0.0f )
+  {
+    mScrollStarted = false;
+    Dali::Toolkit::TextEditor handle( GetOwner() );
+    mScrollStateChangedSignal.Emit( handle, DevelTextEditor::Scroll::FINISHED );
+  }
 }
 
 void TextEditor::OnStageConnect( Dali::Actor actor )
@@ -1667,7 +1692,8 @@ TextEditor::TextEditor()
   mRenderingBackend( DEFAULT_RENDERING_BACKEND ),
   mHasBeenStaged( false ),
   mScrollAnimationEnabled( false ),
-  mScrollBarEnabled( false )
+  mScrollBarEnabled( false ),
+  mScrollStarted( false )
 {
 }
 
index cc864f1..3c2cec4 100644 (file)
@@ -23,6 +23,7 @@
 #include <dali/public-api/animation/animation.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
 #include <dali-toolkit/public-api/controls/scroll-bar/scroll-bar.h>
 #include <dali-toolkit/public-api/controls/text-controls/text-editor.h>
@@ -95,6 +96,11 @@ public:
    */
   Toolkit::TextEditor::InputStyleChangedSignalType& InputStyleChangedSignal();
 
+  /**
+   * @copydoc DevelTextEditor::ScrollStateChangedSignal()
+   */
+  Toolkit::DevelTextEditor::ScrollStateChangedSignalType& ScrollStateChangedSignal();
+
 private: // From Control
 
   /**
@@ -244,6 +250,13 @@ private: // Implementation
   void ApplyScrollPosition();
 
   /**
+   * @brief Callback function for ScrollBar indicator animation finished signal
+   *
+   * Emit ScrollBarStateChanged Signal and toggle mScrollStarted flag to false
+   */
+  void OnScrollIndicatorAnimationFinished( Animation& animation );
+
+  /**
    * Construct a new TextEditor.
    */
   TextEditor();
@@ -269,6 +282,7 @@ private: // Data
   // Signals
   Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal;
   Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal;
+  Toolkit::DevelTextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal;
 
   ImfManager          mImfManager;
   Text::ControllerPtr mController;
@@ -290,6 +304,7 @@ private: // Data
   bool mHasBeenStaged:1;
   bool mScrollAnimationEnabled:1;
   bool mScrollBarEnabled:1;
+  bool mScrollStarted:1;
 };
 
 } // namespace Internal