From: Seoyeon Kim Date: Thu, 6 Aug 2020 04:15:51 +0000 (+0900) Subject: Add a TextEditor property to limit input to maximum characters X-Git-Tag: dali_1.9.25~6^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=a97787d5b7db865cea0b003db309a619877b0144;hp=6450bfaff9367ce929f3c7769be7fcd365be550f Add a TextEditor property to limit input to maximum characters - Added MAX_LENGTH property and MaxLengthReachedSignal to TextEditor Change-Id: I55f97302ff3f60f878ac438a014bb7d967dfdf32 Signed-off-by: Seoyeon Kim --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 51b1cd7..b3decd1 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -101,6 +101,7 @@ const char* const PROPERTY_NAME_PLACEHOLDER = "placehol const char* const PROPERTY_NAME_ENABLE_SHIFT_SELECTION = "enableShiftSelection"; const char* const PROPERTY_NAME_ENABLE_GRAB_HANDLE = "enableGrabHandle"; const char* const PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION = "matchSystemLanguageDirection"; +const char* const PROPERTY_NAME_MAX_LENGTH = "maxLength"; const Vector4 PLACEHOLDER_TEXT_COLOR( 0.8f, 0.8f, 0.8f, 0.8f ); @@ -127,6 +128,7 @@ const std::string DEFAULT_DEVICE_NAME("hwKeyboard"); static bool gTextChangedCallBackCalled; static bool gInputStyleChangedCallbackCalled; +static bool gMaxCharactersCallBackCalled; static Dali::Toolkit::TextEditor::InputStyle::Mask gInputStyleMask; struct CallbackFunctor @@ -158,6 +160,13 @@ static void TestInputStyleChangedCallback( TextEditor control, TextEditor::Input gInputStyleMask = mask; } +static void TestMaxLengthReachedCallback( TextEditor control ) +{ + tet_infoline(" TestMaxLengthReachedCallback"); + + gMaxCharactersCallBackCalled = true; +} + // Generate a KeyEvent to send to Core. Integration::KeyEvent GenerateKey( const std::string& keyName, const std::string& logicalKey, @@ -446,6 +455,7 @@ int UtcDaliTextEditorGetPropertyP(void) DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_SHIFT_SELECTION ) == DevelTextEditor::Property::ENABLE_SHIFT_SELECTION ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_ENABLE_GRAB_HANDLE ) == DevelTextEditor::Property::ENABLE_GRAB_HANDLE ); DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MATCH_SYSTEM_LANGUAGE_DIRECTION ) == DevelTextEditor::Property::MATCH_SYSTEM_LANGUAGE_DIRECTION ); + DALI_TEST_CHECK( editor.GetPropertyIndex( PROPERTY_NAME_MAX_LENGTH ) == DevelTextEditor::Property::MAX_LENGTH ); END_TEST; } @@ -2754,3 +2764,36 @@ int UtcDaliTextEditorGetInputMethodContext(void) END_TEST; } + +int utcDaliTextEditorMaxCharactersReached(void) +{ + ToolkitTestApplication application; + tet_infoline("utcDaliTextEditorMaxCharactersReached"); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + const int maxNumberOfCharacters = 1; + editor.SetProperty( DevelTextEditor::Property::MAX_LENGTH, maxNumberOfCharacters ); + DALI_TEST_EQUALS( editor.GetProperty( DevelTextEditor::Property::MAX_LENGTH ), maxNumberOfCharacters, TEST_LOCATION ); + + editor.SetKeyInputFocus(); + + // connect to the text changed signal. + ConnectionTracker* testTracker = new ConnectionTracker(); + DevelTextEditor::MaxLengthReachedSignal( editor ).Connect(&TestMaxLengthReachedCallback); + bool maxLengthReachedSignal = false; + editor.ConnectSignal( testTracker, "maxLengthReached", CallbackFunctor(&maxLengthReachedSignal) ); + + gMaxCharactersCallBackCalled = false; + + application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "a", "", "a", KEY_A_CODE, 0, 0, Integration::KeyEvent::Down, "a", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + DALI_TEST_CHECK( gMaxCharactersCallBackCalled ); + DALI_TEST_CHECK( maxLengthReachedSignal ); + + 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 index 97ee0fa..b0b248b 100755 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp @@ -33,8 +33,13 @@ InputMethodContext GetInputMethodContext( TextEditor textEditor ) return GetImpl( textEditor ).GetInputMethodContext(); } +MaxLengthReachedSignalType& MaxLengthReachedSignal( TextEditor textEditor ) +{ + return GetImpl( textEditor ).MaxLengthReachedSignal(); +} + } // namespace DevelTextEditor } // namespace Toolkit -} // namespace Dali \ No newline at end of file +} // 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 23f21e8..fe8bc2e 100755 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.h @@ -123,6 +123,12 @@ namespace Property * @details Name "renderingBackend", type Property::INTEGER. */ RENDERING_BACKEND, + + /** + * @brief The maximum number of characters that can be inserted. + * @details Name "maxLength", type Property::INTEGER. + */ + MAX_LENGTH, }; } // namespace Property @@ -135,6 +141,23 @@ namespace Property */ DALI_TOOLKIT_API InputMethodContext GetInputMethodContext( TextEditor textEditor ); +/** + * @brief Max Characters Exceed signal type. + */ +using MaxLengthReachedSignalType = Signal< void ( TextEditor ) >; + +/** + * @brief This signal is emitted when inserted text exceeds the maximum character limit. + * + * A callback of the following type may be connected: + * @code + * void YourCallbackName( TextEditor textEditor ); + * @endcode + * @param[in] textEditor The instance of TextEditor. + * @return The signal to connect to + */ +DALI_TOOLKIT_API MaxLengthReachedSignalType& MaxLengthReachedSignal( TextEditor textEditor ); + } // namespace DevelTextEditor } // namespace Toolkit 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 fa8f3c7..5eaecfa 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -138,9 +137,11 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableShiftSelection", DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "enableGrabHandle", BOOLEAN, ENABLE_GRAB_HANDLE ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "matchSystemLanguageDirection", BOOLEAN, MATCH_SYSTEM_LANGUAGE_DIRECTION ) DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "renderingBackend", INTEGER, RENDERING_BACKEND ) +DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength", INTEGER, MAX_LENGTH ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) +DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "maxLengthReached", SIGNAL_MAX_LENGTH_REACHED ) DALI_TYPE_REGISTRATION_END() @@ -771,6 +772,17 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } break; } + case Toolkit::DevelTextEditor::Property::MAX_LENGTH: + { + if( impl.mController ) + { + const int max = value.Get< int >(); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p MAX_LENGTH %d\n", impl.mController.Get(), max ); + + impl.mController->SetMaximumNumberOfCharacters( max ); + } + break; + } } // switch } // texteditor } @@ -1171,6 +1183,14 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind } break; } + case Toolkit::DevelTextEditor::Property::MAX_LENGTH: + { + if( impl.mController ) + { + value = impl.mController->GetMaximumNumberOfCharacters(); + } + break; + } } //switch } @@ -1182,6 +1202,11 @@ InputMethodContext TextEditor::GetInputMethodContext() return mInputMethodContext; } +DevelTextEditor::MaxLengthReachedSignalType& TextEditor::MaxLengthReachedSignal() +{ + return mMaxLengthReachedSignal; +} + bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ) { Dali::BaseHandle handle( object ); @@ -1197,6 +1222,14 @@ bool TextEditor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface { editor.InputStyleChangedSignal().Connect( tracker, functor ); } + else if( 0 == strcmp( signalName.c_str(), SIGNAL_MAX_LENGTH_REACHED ) ) + { + if( editor ) + { + Internal::TextEditor& editorImpl( GetImpl( editor ) ); + editorImpl.MaxLengthReachedSignal().Connect( tracker, functor ); + } + } else { // signalName does not match any signal @@ -1588,7 +1621,8 @@ void TextEditor::TextChanged() void TextEditor::MaxLengthReached() { - // Nothing to do as TextEditor doesn't emit a max length reached signal. + Dali::Toolkit::TextEditor handle( GetOwner() ); + mMaxLengthReachedSignal.Emit( handle ); } void TextEditor::InputStyleChanged( Text::InputStyle::Mask inputStyleMask ) 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 ba36ad9..a38a5a0 100755 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -80,6 +81,11 @@ public: InputMethodContext GetInputMethodContext(); /** + * @copydoc Dali::Toollkit::TextEditor::MaxLengthReachedSignal() + */ + DevelTextEditor::MaxLengthReachedSignalType& MaxLengthReachedSignal(); + + /** * Connects a callback function with the object's signals. * @param[in] object The object providing the signal. * @param[in] tracker Used to disconnect the signal. @@ -287,6 +293,7 @@ private: // Data Toolkit::TextEditor::TextChangedSignalType mTextChangedSignal; Toolkit::TextEditor::InputStyleChangedSignalType mInputStyleChangedSignal; Toolkit::TextEditor::ScrollStateChangedSignalType mScrollStateChangedSignal; + Toolkit::DevelTextEditor::MaxLengthReachedSignalType mMaxLengthReachedSignal; InputMethodContext mInputMethodContext; Text::ControllerPtr mController;