From 6a9bd26564f5c34ba105b04cec4111523d294bec Mon Sep 17 00:00:00 2001 From: "minho.sun" Date: Thu, 1 Jun 2017 14:22:22 +0900 Subject: [PATCH] Added ScrollStateChangedSignal to TextEditor. 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 --- .../src/dali-toolkit/utc-Dali-TextEditor.cpp | 68 +++++++++++++++++++++- .../controls/text-controls/text-editor-devel.cpp | 43 ++++++++++++++ .../controls/text-controls/text-editor-devel.h | 25 +++++++- dali-toolkit/devel-api/file.list | 1 + .../controls/text-controls/text-editor-impl.cpp | 28 ++++++++- .../controls/text-controls/text-editor-impl.h | 15 +++++ 6 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 9fd6789..c143510 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -18,7 +18,6 @@ #include #include #include - #include #include #include @@ -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 index 0000000..e9292bf --- /dev/null +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp @@ -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 + +// INTERNAL HEADER +#include + +namespace Dali +{ + +namespace Toolkit +{ + +namespace DevelTextEditor +{ + +ScrollStateChangedSignalType& ScrollStateChangedSignal( TextEditor textEditor ) +{ + return Dali::Toolkit::GetImpl( textEditor ).ScrollStateChangedSignal(); +} + +} // namespace DevelText + +} // namespace Toolkit + +} // namespace Dali diff --git a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h index 473adba..f95fc94 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -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 diff --git a/dali-toolkit/devel-api/file.list b/dali-toolkit/devel-api/file.list index fa85816..fe8ef2b 100644 --- a/dali-toolkit/devel-api/file.list +++ b/dali-toolkit/devel-api/file.list @@ -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 \ diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp index ca78a26..1a918cd 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -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 ) { } diff --git a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h index cc864f1..3c2cec4 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -23,6 +23,7 @@ #include // INTERNAL INCLUDES +#include #include #include #include @@ -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 -- 2.7.4