From: ali198724 Date: Fri, 18 Sep 2020 16:16:53 +0000 (+0300) Subject: Text selection refactoring X-Git-Tag: dali_1.9.34~2^2 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=4f4ab5b156cd1dfd274b1c660e836f575362f784 Text selection refactoring 1- Move all of selection text functionality into SelectableControlInterface 2- Support (SelectWholeText, SelectNone, GetSelectedText) in TextEditor Change-Id: I4da66433a09e99be09f6bd027761c3ea49cfc9f5 --- diff --git a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt index 851ca00..4c31f29 100755 --- a/automated-tests/src/dali-toolkit-internal/CMakeLists.txt +++ b/automated-tests/src/dali-toolkit-internal/CMakeLists.txt @@ -28,6 +28,7 @@ SET(TC_SOURCES utc-Dali-Text-Typesetter.cpp utc-Dali-Text-ViewModel.cpp utc-Dali-TextField-internal.cpp + utc-Dali-TextEditor-internal.cpp utc-Dali-TextSelectionPopup-internal.cpp utc-Dali-TextureManager.cpp utc-Dali-Visuals-internal.cpp diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp new file mode 100755 index 0000000..9445be6 --- /dev/null +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextEditor-internal.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2020 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. + * + */ + +#include +#include + +#include +#include + +#include +#include +#include + +using namespace Dali; +using namespace Toolkit; +using namespace Text; + +int UtcDaliTextEditorSelectText(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliTextEditorSelectText" ); + + // Create a text editor + TextEditor textEditor = TextEditor::New(); + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) ); + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello World" ); + + // Add the text editor to the stage + application.GetScene().Add( textEditor ); + + application.SendNotification(); + application.Render(); + + Toolkit::Internal::TextEditor& textEditorImpl = GetImpl( textEditor ); + + application.SendNotification(); + application.Render(); + + // Highlight the whole text + textEditorImpl.SelectWholeText(); + + application.SendNotification(); + application.Render(); + + std::string selectedText = textEditorImpl.GetSelectedText(); + DALI_TEST_CHECK( selectedText == "Hello World" ); + + // Select None + textEditorImpl.SelectNone(); + + application.SendNotification(); + application.Render(); + + selectedText = textEditorImpl.GetSelectedText(); + DALI_TEST_CHECK( selectedText == "" ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextField-internal.cpp b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextField-internal.cpp index a098f73..37d54e1 100755 --- a/automated-tests/src/dali-toolkit-internal/utc-Dali-TextField-internal.cpp +++ b/automated-tests/src/dali-toolkit-internal/utc-Dali-TextField-internal.cpp @@ -112,3 +112,43 @@ int UtcDaliTextFieldMultipleBackgroundText(void) END_TEST; } + +int UtcDaliTextFieldSelectText(void) +{ + ToolkitTestApplication application; + tet_infoline( "UtcDaliTextFieldSelectText" ); + + // Create a text field + TextField textField = TextField::New(); + textField.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) ); + textField.SetProperty( TextField::Property::TEXT, "Hello World" ); + + // Add the text field to the stage + application.GetScene().Add( textField ); + + application.SendNotification(); + application.Render(); + + Toolkit::Internal::TextField& textFieldImpl = GetImpl( textField ); + + application.SendNotification(); + application.Render(); + + // Highlight the whole text + textFieldImpl.SelectWholeText(); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( textFieldImpl.GetSelectedText() == "Hello World" ); + + // Select None + textFieldImpl.SelectNone(); + + application.SendNotification(); + application.Render(); + + DALI_TEST_CHECK( textFieldImpl.GetSelectedText() == "" ); + + END_TEST; +} diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 574cbf9..7a3ce4c 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -2861,6 +2861,107 @@ int utcDaliTextEditorMaxCharactersReached(void) END_TEST; } +int UtcDaliTextEditorSelectWholeText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorSelectWholeText "); + + TextEditor textEditor = TextEditor::New(); + + application.GetScene().Add( textEditor ); + + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( 1u, textEditor.GetChildCount(), TEST_LOCATION ); + + DevelTextEditor::SelectWholeText( textEditor ); + + application.SendNotification(); + application.Render(); + + // Nothing should have been selected. The number of children is still 1 + DALI_TEST_EQUALS( 1u, textEditor.GetChildCount(), TEST_LOCATION ); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + DevelTextEditor::SelectWholeText( textEditor ); + + application.SendNotification(); + application.Render(); + + // Should be 2 children, the stencil and the layer + DALI_TEST_EQUALS( 2u, textEditor.GetChildCount(), TEST_LOCATION ); + + // The offscreen root actor should have two actors: the renderer and the highlight actor. + Actor stencil = textEditor.GetChildAt( 0u ); + + // The highlight actor is drawn first, so is the first actor in the list + Renderer highlight = stencil.GetChildAt( 0u ).GetRendererAt( 0u ); + DALI_TEST_CHECK( highlight ); + + END_TEST; +} + +int UtcDaliTextEditorSelectNone(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorSelectWholeText "); + + TextEditor textEditor = TextEditor::New(); + + application.GetScene().Add( textEditor ); + + textEditor.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textEditor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textEditor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + application.SendNotification(); + application.Render(); + + textEditor.SetProperty( TextEditor::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + // Nothing is selected + std::string selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION ); + + DevelTextEditor::SelectWholeText( textEditor ); + + application.SendNotification(); + application.Render(); + + // whole text is selected + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello world", selectedText, TEST_LOCATION ); + + DevelTextEditor::SelectNone( textEditor ); + + application.SendNotification(); + application.Render(); + + // Nothing is selected + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "", selectedText, TEST_LOCATION ); + + END_TEST; +} + int UtcDaliTextEditorSelectRange(void) { ToolkitTestApplication application; @@ -2882,6 +2983,10 @@ int UtcDaliTextEditorSelectRange(void) textEditor.SetProperty( DevelTextEditor::Property::SELECTED_TEXT_START, 0 ); textEditor.SetProperty( DevelTextEditor::Property::SELECTED_TEXT_END, 5 ); + // Hello is selected + std::string selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 5, TEST_LOCATION ); 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 5858d99..adcff4c 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-editor-devel.cpp @@ -35,6 +35,16 @@ MaxLengthReachedSignalType& MaxLengthReachedSignal(TextEditor textEditor) return GetImpl(textEditor).MaxLengthReachedSignal(); } +void SelectWholeText(TextEditor textEditor) +{ + GetImpl(textEditor).SelectWholeText(); +} + +void SelectNone(TextEditor textEditor) +{ + GetImpl(textEditor).SelectNone(); +} + } // namespace DevelTextEditor } // namespace Toolkit 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 619f91a..0db66e5 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 @@ -84,41 +84,41 @@ enum Type LINE_WRAP_MODE = Dali::Toolkit::TextEditor::Property::LINE_WRAP_MODE, /** - * @brief The text to display when the TextEditor is empty and inactive. - * @details Name "placeholderText", type Property::STRING. - */ + * @brief The text to display when the TextEditor is empty and inactive. + * @details Name "placeholderText", type Property::STRING. + */ PLACEHOLDER_TEXT, /** - * @brief The placeholder-text color. - * @details Name "placeholderTextColor", type Property::VECTOR4. - */ + * @brief The placeholder-text color. + * @details Name "placeholderTextColor", type Property::VECTOR4. + */ PLACEHOLDER_TEXT_COLOR, /** - * @brief Enables Text selection using Shift key. - * @details Name "enableShiftSelection", type Property::BOOLEAN. - */ + * @brief Enables Text selection using Shift key. + * @details Name "enableShiftSelection", type Property::BOOLEAN. + */ ENABLE_SHIFT_SELECTION, /** - * @brief Enables the grab handles for text selection. - * @details Name "enableGrabHandle", type Property::BOOLEAN. - * @note The default value is true, which means the grab handles are enabled by default. - */ + * @brief Enables the grab handles for text selection. + * @details Name "enableGrabHandle", type Property::BOOLEAN. + * @note The default value is true, which means the grab handles are enabled by default. + */ ENABLE_GRAB_HANDLE, /** - * @brief Modifies the default text alignment to match the direction of the system language. - * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write - * @note The default value is false - */ + * @brief Modifies the default text alignment to match the direction of the system language. + * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write + * @note The default value is false + */ MATCH_SYSTEM_LANGUAGE_DIRECTION, /** - * @brief The type or rendering e.g. bitmap-based. - * @details Name "renderingBackend", type Property::INTEGER. - */ + * @brief The type or rendering e.g. bitmap-based. + * @details Name "renderingBackend", type Property::INTEGER. + */ RENDERING_BACKEND, /** @@ -141,9 +141,16 @@ enum Type /** * @brief The Editable state of control. - * @details Name "editable", type Property::BOOL. + * @details Name "enableEditing", type Property::BOOLEAN. */ ENABLE_EDITING, + + /** + * @brief The selected text in UTF-8 format. + * @details Name "selectedText", type Property::STRING. + * @note This property is read-only. + */ + SELECTED_TEXT, }; } // namespace Property @@ -173,6 +180,20 @@ using MaxLengthReachedSignalType = Signal; */ DALI_TOOLKIT_API MaxLengthReachedSignalType& MaxLengthReachedSignal(TextEditor textEditor); +/** + * @brief Select the whole text of TextEditor. + * + * @param[in] textEditor The instance of TextEditor. + */ +DALI_TOOLKIT_API void SelectWholeText(TextEditor textEditor); + +/** + * @brief Unselect the whole text of TextEditor. + * + * @param[in] textEditor The instance of TextEditor. + */ +DALI_TOOLKIT_API void SelectNone(TextEditor textEditor); + } // namespace DevelTextEditor } // namespace Toolkit diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h index 824d83c..cec1709 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.h @@ -84,51 +84,51 @@ enum ELLIPSIS = Dali::Toolkit::TextField::Property::ELLIPSIS, /** - * @brief Enables Text selection using Shift key. - * @details Name "enableShiftSelection", type Property::BOOLEAN. - */ + * @brief Enables Text selection using Shift key. + * @details Name "enableShiftSelection", type Property::BOOLEAN. + */ ENABLE_SHIFT_SELECTION = ELLIPSIS + 1, /** - * @brief Enables the grab handles for text selection. - * @details Name "enableGrabHandle", type Property::BOOLEAN. - * @note The default value is true, which means the grab handles are enabled by default. - */ + * @brief Enables the grab handles for text selection. + * @details Name "enableGrabHandle", type Property::BOOLEAN. + * @note The default value is true, which means the grab handles are enabled by default. + */ ENABLE_GRAB_HANDLE = ELLIPSIS + 2, /** - * @brief Modifies the default text alignment to match the direction of the system language. - * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write - * @note The default value is false - */ + * @brief Modifies the default text alignment to match the direction of the system language. + * @details Name "matchSystemLanguageDirection", type (Property::BOOLEAN), Read/Write + * @note The default value is false + */ MATCH_SYSTEM_LANGUAGE_DIRECTION = ELLIPSIS + 3, /** - * @brief Enables the grab handle popup for text selection. - * @details Name "enableGrabHandlePopup", type Property::BOOLEAN. - * @note The default value is true, which means the grab handle popup is enabled by default. - */ + * @brief Enables the grab handle popup for text selection. + * @details Name "enableGrabHandlePopup", type Property::BOOLEAN. + * @note The default value is true, which means the grab handle popup is enabled by default. + */ ENABLE_GRAB_HANDLE_POPUP = ELLIPSIS + 4, /** - * @brief The default text background parameters. - * @details Name "textBackground", type Property::VECTOR4. - * @note Use "textBackground" as property name to avoid conflict with Control's "background" property. - * @note The default value is Color::TRANSPARENT. - */ + * @brief The default text background parameters. + * @details Name "textBackground", type Property::VECTOR4. + * @note Use "textBackground" as property name to avoid conflict with Control's "background" property. + * @note The default value is Color::TRANSPARENT. + */ BACKGROUND = ELLIPSIS + 5, /** - * @brief The selected text in UTF-8 format. - * @details Name "selectedText", type Property::STRING. - * @note This property is read-only. - */ + * @brief The selected text in UTF-8 format. + * @details Name "selectedText", type Property::STRING. + * @note This property is read-only. + */ SELECTED_TEXT = ELLIPSIS + 6, /** - * @brief The type or rendering e.g. bitmap-based. - * @details Name "renderingBackend", type Property::INTEGER. - */ + * @brief The type or rendering e.g. bitmap-based. + * @details Name "renderingBackend", type Property::INTEGER. + */ RENDERING_BACKEND = ELLIPSIS + 7, /** @@ -145,7 +145,7 @@ enum /** * @brief The Editable state of control. - * @details Name "editable", type Property::BOOL. + * @details Name "enableEditing", type Property::BOOLEAN. */ ENABLE_EDITING, 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 4224df2..60db674 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -143,6 +143,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextEditor, "maxLength", 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, "enableEditing", BOOLEAN, ENABLE_EDITING ) +DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextEditor, "selectedText", STRING, SELECTED_TEXT ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "textChanged", SIGNAL_TEXT_CHANGED ) DALI_SIGNAL_REGISTRATION( Toolkit, TextEditor, "inputStyleChanged", SIGNAL_INPUT_STYLE_CHANGED ) @@ -701,22 +702,16 @@ void TextEditor::SetProperty( BaseObject* object, Property::Index index, const P } case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_START: { - if( impl.mController ) - { - uint32_t start = static_cast(value.Get< int >()); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start ); - impl.SetTextSelectionRange( &start, nullptr ); - } + uint32_t start = static_cast(value.Get< int >()); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start ); + impl.SetTextSelectionRange( &start, nullptr ); break; } case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_END: { - if( impl.mController ) - { - uint32_t end = static_cast(value.Get< int >()); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end ); - impl.SetTextSelectionRange( nullptr, &end ); - } + uint32_t end = static_cast(value.Get< int >()); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextEditor %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end ); + impl.SetTextSelectionRange( nullptr, &end ); break; } case Toolkit::DevelTextEditor::Property::ENABLE_EDITING: @@ -1040,6 +1035,11 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind value = impl.mController->GetMaximumNumberOfCharacters(); break; } + case Toolkit::DevelTextEditor::Property::SELECTED_TEXT: + { + value = impl.mController->GetSelectedText( ); + break; + } case Toolkit::DevelTextEditor::Property::SELECTED_TEXT_START: { Uint32Pair range = impl.GetTextSelectionRange(); @@ -1063,6 +1063,33 @@ Property::Value TextEditor::GetProperty( BaseObject* object, Property::Index ind return value; } +void TextEditor::SelectWholeText() +{ + if( mController && mController->IsShowingRealText() ) + { + mController->SelectWholeText(); + SetKeyInputFocus(); + } +} + +void TextEditor::SelectNone() +{ + if( mController && mController->IsShowingRealText() ) + { + mController->SelectNone(); + } +} + +string TextEditor::GetSelectedText() const +{ + string selectedText = ""; + if( mController && mController->IsShowingRealText() ) + { + selectedText = mController->GetSelectedText( ); + } + return selectedText; +} + InputMethodContext TextEditor::GetInputMethodContext() { return mInputMethodContext; 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 f89520e..2aca941 100755 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -216,6 +216,21 @@ public: Uint32Pair GetTextSelectionRange() const override; /** + * @copydoc Text::SelectableControlInterface::SelectWholeText() + */ + void SelectWholeText() override; + + /** + * @copydoc Text::SelectableControlInterface::SelectNone() + */ + void SelectNone() override; + + /** + * @copydoc Text::SelectableControlInterface::GetSelectedText() + */ + string GetSelectedText() const override; + + /** * @copydoc Text::EditableControlInterface::IsEditable() */ bool IsEditable() const override; diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp index c038d08..a85a342 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -714,22 +714,16 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr } case Toolkit::DevelTextField::Property::SELECTED_TEXT_START: { - if( impl.mController ) - { - uint32_t start = static_cast(value.Get< int >()); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start ); - impl.SetTextSelectionRange( &start, nullptr ); - } + uint32_t start = static_cast(value.Get< int >()); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_START %d\n", impl.mController.Get(), start ); + impl.SetTextSelectionRange( &start, nullptr ); break; } case Toolkit::DevelTextField::Property::SELECTED_TEXT_END: { - if( impl.mController ) - { - uint32_t end = static_cast(value.Get< int >()); - DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end ); - impl.SetTextSelectionRange( nullptr, &end ); - } + uint32_t end = static_cast(value.Get< int >()); + DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p SELECTED_TEXT_END %d\n", impl.mController.Get(), end ); + impl.SetTextSelectionRange( nullptr, &end ); break; } case Toolkit::DevelTextField::Property::ENABLE_EDITING: @@ -1089,7 +1083,7 @@ void TextField::SelectWholeText() { if( mController && mController->IsShowingRealText() ) { - mController->SelectEvent( 0.f, 0.f, SelectionType::ALL ); + mController->SelectWholeText(); SetKeyInputFocus(); } } @@ -1098,9 +1092,18 @@ void TextField::SelectNone() { if( mController && mController->IsShowingRealText() ) { - mController->SelectEvent( 0.f, 0.f, SelectionType::NONE ); - SetKeyInputFocus(); + mController->SelectNone(); + } +} + +string TextField::GetSelectedText() const +{ + string selectedText = ""; + if( mController && mController->IsShowingRealText() ) + { + selectedText = mController->GetSelectedText( ); } + return selectedText; } void TextField::SetTextSelectionRange(const uint32_t *start, const uint32_t *end) diff --git a/dali-toolkit/internal/controls/text-controls/text-field-impl.h b/dali-toolkit/internal/controls/text-controls/text-field-impl.h index 165234b..329d7b5 100755 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -103,16 +103,6 @@ public: */ Toolkit::TextField::InputStyleChangedSignalType& InputStyleChangedSignal(); - /** - * @brief Called to select the whole texts. - */ - void SelectWholeText(); - - /** - * @brief Called to unselect the whole texts. - */ - void SelectNone(); - private: // From Control /** @@ -217,6 +207,21 @@ public: Uint32Pair GetTextSelectionRange() const override; /** + * @copydoc Text::SelectableControlInterface::SelectWholeText() + */ + void SelectWholeText() override; + + /** + * @copydoc Text::SelectableControlInterface::SelectNone() + */ + void SelectNone() override; + + /** + * @copydoc Text::SelectableControlInterface::GetSelectedText() + */ + string GetSelectedText() const override; + + /** * @copydoc Text::EditableControlInterface::IsEditable() */ bool IsEditable() const override; diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index ca02bac..797ae32 100755 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -3214,6 +3214,26 @@ Uint32Pair Controller::GetTextSelectionRange() const return mImpl->GetTextSelectionRange(); } +void Controller::SelectWholeText() +{ + SelectEvent( 0.f, 0.f, SelectionType::ALL ); +} + +void Controller::SelectNone() +{ + SelectEvent( 0.f, 0.f, SelectionType::NONE ); +} + +string Controller::GetSelectedText() const +{ + string text; + if( EventData::SELECTING == mImpl->mEventData->mState ) + { + mImpl->RetrieveSelection( text, false ); + } + return text; +} + InputMethodContext::CallbackData Controller::OnInputMethodContextEvent( InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent ) { // Whether the text needs to be relaid-out. @@ -3926,16 +3946,6 @@ bool Controller::RemoveSelectedText() return textRemoved; } -std::string Controller::GetSelectedText() -{ - std::string text; - if( EventData::SELECTING == mImpl->mEventData->mState ) - { - mImpl->RetrieveSelection( text, false ); - } - return text; -} - // private : Relayout. bool Controller::DoRelayout( const Size& size, diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index e523dd2..3faab75 100755 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1506,6 +1506,21 @@ public: // Text-input Event Queuing. Uint32Pair GetTextSelectionRange() const; /** + * @copydoc Text::SelectableControlInterface::SelectWholeText() + */ + void SelectWholeText(); + + /** + * @copydoc Text::SelectableControlInterface::SelectNone() + */ + void SelectNone(); + + /** + * @copydoc Text::SelectableControlInterface::GetSelectedText() + */ + string GetSelectedText() const; + + /** * @copydoc Text::EditableControlInterface::IsEditable() */ virtual bool IsEditable() const; @@ -1543,13 +1558,6 @@ public: // Text-input Event Queuing. */ Actor CreateBackgroundActor(); - /** - * @brief Retrive Selected text. - * - * @return The seleced text. - */ - std::string GetSelectedText(); - protected: // Inherit from Text::Decorator::ControllerInterface. /** diff --git a/dali-toolkit/internal/text/text-selectable-control-interface.h b/dali-toolkit/internal/text/text-selectable-control-interface.h index fe70abb..65a35ca 100644 --- a/dali-toolkit/internal/text/text-selectable-control-interface.h +++ b/dali-toolkit/internal/text/text-selectable-control-interface.h @@ -25,6 +25,7 @@ namespace Toolkit { using Uint32Pair = std::pair; +using string = std::string; namespace Text { @@ -52,6 +53,22 @@ public: * @return pair contains start and end positions. */ virtual Uint32Pair GetTextSelectionRange() const = 0; + + /** + * @brief Called to select the whole texts. + */ + virtual void SelectWholeText() = 0; + + /** + * @brief Called to unselect the whole texts. + */ + virtual void SelectNone() = 0; + + /** + * @brief Retrive Selected text. + * @return The seletced text. + */ + virtual string GetSelectedText() const = 0; }; } // namespace Text