From: Sara Samara Date: Mon, 2 Aug 2021 12:41:26 +0000 (+0300) Subject: Support Public APIs - CopyText, CutText & PasteText X-Git-Tag: dali_2.0.41~6 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=0f19aa986501f6b51de786a08b1fcfda00b849d8 Support Public APIs - CopyText, CutText & PasteText with the following prototypes and descriptions: string CopyText(TextEditor textEditor) or string CopyText(TextField textField) This function will copy the previously selected string into the clipboard and will return it. string CutText(TextEditor textEditor) or string CutText(TextField textField) This function will cut the previously selected string into the clipboard and will return it. void PasteText(TextEditor textEditor) or void PasteText(TextField textField This function will paste the most recent string in the clipboard stack into the text control. Change-Id: I7dc8156e636f95b8acf8c350bfc7827419e239ca --- diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp index 9aef457..0d0b8bc 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextEditor.cpp @@ -4004,6 +4004,297 @@ int UtcDaliToolkitTextEditorEllipsisPositionProperty(void) END_TEST; } +int UtcDaliTextEditorCopyText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorCopyText "); + + TextEditor textEditor = TextEditor::New(); + + std::string selectedText = ""; + std::string copiedText = ""; + + 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(); + + // Hello is selected + DevelTextEditor::SelectText( textEditor, 0, 5 ); + + application.SendNotification(); + application.Render(); + + 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 ); + + // Hello is copied + copiedText = DevelTextEditor::CopyText( textEditor ); + DALI_TEST_EQUALS( "Hello", copiedText, TEST_LOCATION ); + + // world is selected + DevelTextEditor::SelectText( textEditor, 6, 11 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 6, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 11, TEST_LOCATION ); + + // world is copied + copiedText = DevelTextEditor::CopyText( textEditor ); + DALI_TEST_EQUALS( "world", copiedText, TEST_LOCATION ); + + // "lo wo" is selected + DevelTextEditor::SelectText( textEditor, 3, 8 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "lo wo", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 3, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 8, TEST_LOCATION ); + + // "lo wo" is copied + copiedText = DevelTextEditor::CopyText( textEditor ); + DALI_TEST_EQUALS( "lo wo", copiedText, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorCutText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorCutText "); + + TextEditor textEditor = TextEditor::New(); + + std::string selectedText = ""; + + 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(); + + // Hello is selected + DevelTextEditor::SelectText( textEditor, 0, 5 ); + + application.SendNotification(); + application.Render(); + + 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 ); + + // Hello is cut + DALI_TEST_EQUALS( "Hello", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), " world", TEST_LOCATION ); + + // " w" is selected + DevelTextEditor::SelectText( textEditor, 0, 2 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( " w", 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(), 2, TEST_LOCATION ); + + // " w" is cut + DALI_TEST_EQUALS( " w", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "orld", TEST_LOCATION ); + + // Test Cut from the middle + + // "rl" is selected + DevelTextEditor::SelectText( textEditor, 1, 3 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "rl", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 3, TEST_LOCATION ); + + // "rl" is cut + DALI_TEST_EQUALS( "rl", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "od", TEST_LOCATION ); + + // Test Cut from the end + + // "d" is selected + DevelTextEditor::SelectText( textEditor, 1, 2 ); + + application.SendNotification(); + application.Render(); + + selectedText = textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "d", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_START ).Get(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( textEditor.GetProperty( DevelTextEditor::Property::SELECTED_TEXT_END ).Get(), 2, TEST_LOCATION ); + + // "d" is cut + DALI_TEST_EQUALS( "d", DevelTextEditor::CutText( textEditor ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textEditor.GetProperty( TextEditor::Property::TEXT ).Get(), "o", TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextEditorPasteText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextEditorPasteText "); + + TextEditor editor = TextEditor::New(); + DALI_TEST_CHECK( editor ); + + application.GetScene().Add( editor ); + + std::string cutText = ""; + std::string copiedText = ""; + + editor.SetProperty( TextEditor::Property::TEXT, "Hello\nworld\nHello world" ); + editor.SetProperty( TextEditor::Property::POINT_SIZE, 10.f ); + editor.SetProperty( Actor::Property::SIZE, Vector2( 100.f, 50.f ) ); + editor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + editor.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT ); + + // Avoid a crash when core load gl resources. + application.GetGlAbstraction().SetCheckFramebufferStatusResult( GL_FRAMEBUFFER_COMPLETE ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Tap on the text editor + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Move to second line of the text. + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Select some text in the right of the current cursor position + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_SHIFT_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Cut the selected text + cutText = DevelTextEditor::CutText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "wor", cutText, TEST_LOCATION ); + DALI_TEST_EQUALS( "Hello\nld\nHello world", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + // Select some text in the left of the current cursor position + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_SHIFT_LEFT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "",DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_LEFT, KEY_SHIFT_MODIFIER, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Copy the selected text + copiedText = DevelTextEditor::CopyText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "lo\n", copiedText, TEST_LOCATION ); + DALI_TEST_EQUALS( "Hello\nld\nHello world", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + + // Move the cursor to the third line + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_DOWN, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Paste the selected text at the current cursor position + DevelTextEditor::PasteText(editor); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "Hello\nld\nHello lo\nworld", editor.GetProperty( TextEditor::Property::TEXT ), TEST_LOCATION ); + + END_TEST; +} int UtcDaliTextEditorLineSpacing(void) { ToolkitTestApplication application; diff --git a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp index eafc4d5..7e9c6eb 100644 --- a/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp +++ b/automated-tests/src/dali-toolkit/utc-Dali-TextField.cpp @@ -120,7 +120,6 @@ const std::string DEFAULT_FONT_DIR( "/resources/fonts" ); const int KEY_RETURN_CODE = 36; const int KEY_A_CODE = 38; const int KEY_D_CODE = 40; - const int KEY_SHIFT_MODIFIER = 257; const std::string DEFAULT_DEVICE_NAME("hwKeyboard"); @@ -4002,6 +4001,286 @@ int UtcDaliToolkitTextFieldEllipsisPositionProperty(void) END_TEST; } +int UtcDaliTextFieldCopyText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextFieldCopyText "); + + TextField textField = TextField::New(); + + std::string selectedText = ""; + std::string copiedText = ""; + + application.GetScene().Add( textField ); + + textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textField.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(); + + textField.SetProperty( TextField::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + // Hello is selected + DevelTextField::SelectText( textField, 0, 5 ); + + application.SendNotification(); + application.Render(); + + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 5, TEST_LOCATION ); + + // Hello is copied + copiedText = DevelTextField::CopyText( textField ); + DALI_TEST_EQUALS( "Hello", copiedText, TEST_LOCATION ); + + // world is selected + DevelTextField::SelectText( textField, 6, 11 ); + + application.SendNotification(); + application.Render(); + + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "world", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 6, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 11, TEST_LOCATION ); + + // world is copied + copiedText = DevelTextField::CopyText( textField ); + DALI_TEST_EQUALS( "world", copiedText, TEST_LOCATION ); + + // "lo wo" is selected + DevelTextField::SelectText( textField, 3, 8 ); + + application.SendNotification(); + application.Render(); + + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "lo wo", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 3, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 8, TEST_LOCATION ); + + // "lo wo" is copied + copiedText = DevelTextField::CopyText( textField ); + DALI_TEST_EQUALS( "lo wo", copiedText, TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextFieldCutText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextFieldCutText "); + + TextField textField = TextField::New(); + + std::string selectedText = ""; + + application.GetScene().Add( textField ); + + textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textField.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(); + + textField.SetProperty( TextField::Property::TEXT, "Hello world" ); + + application.SendNotification(); + application.Render(); + + // Hello is selected + DevelTextField::SelectText( textField, 0, 5 ); + + application.SendNotification(); + application.Render(); + + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "Hello", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 5, TEST_LOCATION ); + + // Hello is cut + DALI_TEST_EQUALS( "Hello", DevelTextField::CutText( textField ), TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), " world", TEST_LOCATION ); + + // " w" is selected + DevelTextField::SelectText( textField, 0, 2 ); + + application.SendNotification(); + application.Render(); + + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( " w", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 0, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 2, TEST_LOCATION ); + + // " w" is cut + DALI_TEST_EQUALS( " w", DevelTextField::CutText( textField ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), "orld", TEST_LOCATION ); + + // Test Cut from the middle + + // "rl" is selected + DevelTextField::SelectText( textField, 1, 3 ); + + application.SendNotification(); + application.Render(); + + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "rl", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 3, TEST_LOCATION ); + + // "rl" is cut + DALI_TEST_EQUALS( "rl", DevelTextField::CutText( textField ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), "od", TEST_LOCATION ); + + // Test Cut from the end + + // "d" is selected + DevelTextField::SelectText( textField, 1, 2 ); + + application.SendNotification(); + application.Render(); + + selectedText = textField.GetProperty( DevelTextField::Property::SELECTED_TEXT ).Get(); + DALI_TEST_EQUALS( "d", selectedText, TEST_LOCATION ); + + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_START ).Get(), 1, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( DevelTextField::Property::SELECTED_TEXT_END ).Get(), 2, TEST_LOCATION ); + + // "d" is cut + DALI_TEST_EQUALS( "d", DevelTextField::CutText( textField ), TEST_LOCATION ); + + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), "o", TEST_LOCATION ); + + END_TEST; +} + +int UtcDaliTextFieldPasteText(void) +{ + ToolkitTestApplication application; + tet_infoline(" UtcDaliTextFieldPasteText "); + + TextField textField = TextField::New(); + + application.GetScene().Add( textField ); + + std::string cutText = ""; + std::string copiedText = ""; + + textField.SetProperty( Actor::Property::SIZE, Vector2( 300.f, 50.f ) ); + textField.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT ); + textField.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(); + + textField.SetProperty( TextField::Property::TEXT, "Hello World" ); + + application.SendNotification(); + application.Render(); + + // Tap on the text editor + TestGenerateTap( application, 3.0f, 25.0f ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Select some text in the right of the current cursor position + DevelTextField::SelectText( textField, 0, 3 ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Cut the selected text + cutText = DevelTextField::CutText(textField); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "Hel", cutText, TEST_LOCATION ); + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), "lo World", TEST_LOCATION ); + + DevelTextField::SelectText( textField, 0, 3 ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Copy the selected text + copiedText = DevelTextField::CopyText(textField); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( "lo ", copiedText, TEST_LOCATION ); + DALI_TEST_EQUALS( "lo World", textField.GetProperty( TextField::Property::TEXT ), TEST_LOCATION ); + + // Move the cursor to the end of the line + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + application.ProcessEvent( GenerateKey( "", "", "", DALI_KEY_CURSOR_RIGHT, 0, 0, Integration::KeyEvent::DOWN, "", DEFAULT_DEVICE_NAME, Device::Class::NONE, Device::Subclass::NONE ) ); + + // Render and notify + application.SendNotification(); + application.Render(); + + // Paste the selected text at the current cursor position + DevelTextField::PasteText(textField); + + // Render and notify + application.SendNotification(); + application.Render(); + + DALI_TEST_EQUALS( textField.GetProperty( TextField::Property::TEXT ).Get(), "lo Worldlo ", TEST_LOCATION ); + + END_TEST; +} int utcDaliTextFieldCursorPositionChangedSignal(void) { ToolkitTestApplication application; 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 33fc4e7..74a57e6 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 @@ -75,6 +75,21 @@ void ScrollBy(TextEditor textEditor, Vector2 scroll) GetImpl(textEditor).ScrollBy(scroll); } +string CopyText(TextEditor textEditor) +{ + return GetImpl(textEditor).CopyText(); +} + +string CutText(TextEditor textEditor) +{ + return GetImpl(textEditor).CutText(); +} + +void PasteText(TextEditor textEditor) +{ + GetImpl(textEditor).PasteText(); +} + } // 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 53a63e2..345368d 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 @@ -433,6 +433,29 @@ DALI_TOOLKIT_API void SelectText(TextEditor textEditor, const uint32_t start, co */ DALI_TOOLKIT_API void ScrollBy(TextEditor textEditor, Vector2 scroll); +/** + * @brief Copy and return the selected text of TextEditor. + * + * @param[in] textEditor The instance of TextEditor. + * @return The copied text. + */ +DALI_TOOLKIT_API std::string CopyText(TextEditor textEditor); + +/** + * @brief Cut and return the selected text of TextEditor. + * + * @param[in] textEditor The instance of TextEditor. + * @return The cut text. + */ +DALI_TOOLKIT_API std::string CutText(TextEditor textEditor); + +/** + * @brief Paste the most recent clipboard text item into the TextEditor. + * + * @param[in] textEditor The instance of TextEditor. + */ +DALI_TOOLKIT_API void PasteText(TextEditor textEditor); + } // namespace DevelTextEditor } // namespace Toolkit diff --git a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp index 0d9ef15..e9a609f 100644 --- a/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp +++ b/dali-toolkit/devel-api/controls/text-controls/text-field-devel.cpp @@ -65,6 +65,21 @@ void SelectText(TextField textField, const uint32_t start, const uint32_t end) GetImpl(textField).SelectText(start, end); } +string CopyText(TextField textField) +{ + return GetImpl(textField).CopyText(); +} + +string CutText(TextField textField) +{ + return GetImpl(textField).CutText(); +} + +void PasteText(TextField textField) +{ + GetImpl(textField).PasteText(); +} + } // namespace DevelTextField } // 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 59f192d..4dff21d 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 @@ -347,6 +347,29 @@ DALI_TOOLKIT_API void SelectNone(TextField textField); */ DALI_TOOLKIT_API void SelectText(TextField textField, const uint32_t start, const uint32_t end); +/** + * @brief Copy and return the selected text of TextField. + * + * @param[in] textField The instance of TextField. + * @return The copied text. + */ +DALI_TOOLKIT_API std::string CopyText(TextField textField); + +/** + * @brief Cut and return the selected text of TextField. + * + * @param[in] textField The instance of TextField. + * @return The cut text. + */ +DALI_TOOLKIT_API std::string CutText(TextField textField); + +/** + * @brief Paste the most recent clipboard text item into the TextField. + * + * @param[in] textField The instance of TextField. + */ +DALI_TOOLKIT_API void PasteText(TextField textField); + } // namespace DevelTextField } // 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 8236064..7a3b4ba 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp @@ -1263,6 +1263,35 @@ void TextEditor::SelectText(const uint32_t start, const uint32_t end) } } +string TextEditor::CopyText() +{ + string copiedText = ""; + if(mController && mController->IsShowingRealText()) + { + copiedText = mController->CopyText(); + } + return copiedText; +} + +string TextEditor::CutText() +{ + string cutText = ""; + if(mController && mController->IsShowingRealText()) + { + cutText = mController->CutText(); + } + return cutText; +} + +void TextEditor::PasteText() +{ + if(mController) + { + SetKeyInputFocus(); //Giving focus to the editor that was passed to the PasteText in case the passed editor (current editor) doesn't have focus. + mController->PasteText(); + } +} + void TextEditor::ScrollBy(Vector2 scroll) { if(mController && mController->IsShowingRealText()) 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 d76b41b..aff671a 100644 --- a/dali-toolkit/internal/controls/text-controls/text-editor-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-editor-impl.h @@ -326,6 +326,21 @@ public: */ void SetEditable(bool editable) override; + /** + * @copydoc Text::EditableControlInterface::CopyText() + */ + string CopyText() override; + + /** + * @copydoc Text::EditableControlInterface::CutText() + */ + string CutText() override; + + /** + * @copydoc Text::EditableControlInterface::PasteText() + */ + void PasteText() override; + // From AnchorControlInterface /** 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 a806c70..c6fd205 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.cpp @@ -1216,6 +1216,35 @@ Uint32Pair TextField::GetTextSelectionRange() const return range; } +string TextField::CopyText() +{ + string copiedText = ""; + if(mController && mController->IsShowingRealText()) + { + copiedText = mController->CopyText(); + } + return copiedText; +} + +string TextField::CutText() +{ + string cutText = ""; + if(mController && mController->IsShowingRealText()) + { + cutText = mController->CutText(); + } + return cutText; +} + +void TextField::PasteText() +{ + if(mController) + { + SetKeyInputFocus(); //Giving focus to the field that was passed to the PasteText in case the passed field (current field) doesn't have focus. + mController->PasteText(); + } +} + InputMethodContext TextField::GetInputMethodContext() { return mInputMethodContext; 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 5cc7e78..0b24ff0 100644 --- a/dali-toolkit/internal/controls/text-controls/text-field-impl.h +++ b/dali-toolkit/internal/controls/text-controls/text-field-impl.h @@ -298,6 +298,21 @@ public: */ void SetEditable(bool editable) override; + /** + * @copydoc Dali::EditableControlInterface::CopyText() + */ + string CopyText() override; + + /** + * @copydoc Dali::EditableControlInterface::CutText() + */ + string CutText() override; + + /** + * @copydoc Text::EditableControlInterface::PasteText() + */ + void PasteText() override; + // From AnchorControlInterface /** diff --git a/dali-toolkit/internal/text/text-controller-event-handler.cpp b/dali-toolkit/internal/text/text-controller-event-handler.cpp index bf677e5..5d78405 100644 --- a/dali-toolkit/internal/text/text-controller-event-handler.cpp +++ b/dali-toolkit/internal/text/text-controller-event-handler.cpp @@ -952,43 +952,17 @@ void Controller::EventHandler::TextPopupButtonTouched(Controller& controller, Da { case Toolkit::TextSelectionPopup::CUT: { - if(!controller.IsEditable()) return; - controller.mImpl->SendSelectionToClipboard(true); // Synchronous call to modify text - controller.mImpl->mOperationsPending = ALL_OPERATIONS; - - if((0u != controller.mImpl->mModel->mLogicalModel->mText.Count()) || - !controller.mImpl->IsPlaceholderAvailable()) - { - controller.mImpl->QueueModifyEvent(ModifyEvent::TEXT_DELETED); - } - else - { - controller.ShowPlaceholderText(); - } - - controller.mImpl->mEventData->mUpdateCursorPosition = true; - controller.mImpl->mEventData->mScrollAfterDelete = true; - - controller.mImpl->RequestRelayout(); - - if(NULL != controller.mImpl->mEditableControlInterface) - { - controller.mImpl->mEditableControlInterface->TextChanged(true); - } + controller.CutText(); break; } case Toolkit::TextSelectionPopup::COPY: { - controller.mImpl->SendSelectionToClipboard(false); // Text not modified - - controller.mImpl->mEventData->mUpdateCursorPosition = true; - - controller.mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup + controller.CopyText(); break; } case Toolkit::TextSelectionPopup::PASTE: { - controller.mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item + controller.PasteText(); break; } case Toolkit::TextSelectionPopup::SELECT: diff --git a/dali-toolkit/internal/text/text-controller.cpp b/dali-toolkit/internal/text/text-controller.cpp index b058e26..30c6e04 100644 --- a/dali-toolkit/internal/text/text-controller.cpp +++ b/dali-toolkit/internal/text/text-controller.cpp @@ -1913,6 +1913,59 @@ string Controller::GetSelectedText() const return text; } +string Controller::CopyText() +{ + string text; + mImpl->RetrieveSelection(text, false); + mImpl->SendSelectionToClipboard(false); // Text not modified + + mImpl->mEventData->mUpdateCursorPosition = true; + + mImpl->RequestRelayout(); // Cursor, Handles, Selection Highlight, Popup + + return text; +} + +string Controller::CutText() +{ + string text; + mImpl->RetrieveSelection(text, false); + + if(!IsEditable()) + { + return ""; + } + + mImpl->SendSelectionToClipboard(true); // Synchronous call to modify text + mImpl->mOperationsPending = ALL_OPERATIONS; + + if((0u != mImpl->mModel->mLogicalModel->mText.Count()) || + !mImpl->IsPlaceholderAvailable()) + { + mImpl->QueueModifyEvent(ModifyEvent::TEXT_DELETED); + } + else + { + ShowPlaceholderText(); + } + + mImpl->mEventData->mUpdateCursorPosition = true; + mImpl->mEventData->mScrollAfterDelete = true; + + mImpl->RequestRelayout(); + + if(nullptr != mImpl->mEditableControlInterface) + { + mImpl->mEditableControlInterface->TextChanged(true); + } + return text; +} + +void Controller::PasteText() +{ + mImpl->RequestGetTextFromClipboard(); // Request clipboard service to retrieve an item +} + InputMethodContext::CallbackData Controller::OnInputMethodContextEvent(InputMethodContext& inputMethodContext, const InputMethodContext::EventData& inputMethodContextEvent) { return EventHandler::OnInputMethodContextEvent(*this, inputMethodContext, inputMethodContextEvent); diff --git a/dali-toolkit/internal/text/text-controller.h b/dali-toolkit/internal/text/text-controller.h index 109be1a..9302cf5 100644 --- a/dali-toolkit/internal/text/text-controller.h +++ b/dali-toolkit/internal/text/text-controller.h @@ -1633,6 +1633,21 @@ public: // Text-input Event Queuing. void SelectWholeText(); /** + * @copydoc Text::EditableControlInterface::CopyText() + */ + string CopyText(); + + /** + * @copydoc Text::EditableControlInterface::CutText() + */ + string CutText(); + + /** + * @copydoc Text::EditableControlInterface::PasteText() + */ + void PasteText(); + + /** * @copydoc Text::SelectableControlInterface::SelectNone() */ void SelectNone(); @@ -1751,8 +1766,7 @@ private: // Update. void InsertText(const std::string& text, InsertType type); /** - * @brief Paste given string into Text model - * @param[in] stringToPaste this string will be inserted into the text model + * @copydoc Text::EditableControlInterface::PasteText() */ void PasteText(const std::string& stringToPaste); diff --git a/dali-toolkit/internal/text/text-editable-control-interface.h b/dali-toolkit/internal/text/text-editable-control-interface.h index cd071f2..12d4256 100644 --- a/dali-toolkit/internal/text/text-editable-control-interface.h +++ b/dali-toolkit/internal/text/text-editable-control-interface.h @@ -112,6 +112,23 @@ public: * @param[in] editable The editable status. */ virtual void SetEditable(bool editable) = 0; + + /** + * @brief Called to copy the selected text. + * @return The copied text. + */ + virtual string CopyText() = 0; + + /** + * @brief Called to cut the selected text. + * @return The cut text. + */ + virtual string CutText() = 0; + + /** + * @brief Called to paste the most recent clipboard text item into the control. + */ + virtual void PasteText() = 0; }; } // namespace Text